深入浅出python机器学习_9.1.5_通过数据预处理提高模型的准确率_MinMaxScaler
生活随笔
收集整理的這篇文章主要介紹了
深入浅出python机器学习_9.1.5_通过数据预处理提高模型的准确率_MinMaxScaler
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
# 導入紅酒數(shù)據(jù)集from sklearn.datasets import load_wine# 導入MLP神經(jīng)網(wǎng)絡from sklearn.neural_network import MLPClassifier# 導入數(shù)據(jù)集拆分工具from sklearn.model_selection import train_test_split# 建立訓練集個測試集wine=load_wine()X_train,X_test,y_train,y_test=train_test_split(wine.data,wine.target,random_state=62)# 打印數(shù)據(jù)形態(tài)print(X_train.shape,X_test.shape)
(133, 13) (45, 13)
# 設定MLP神經(jīng)網(wǎng)絡的參數(shù)mlp=MLPClassifier(hidden_layer_sizes=[100,100],max_iter=400,random_state=62)# 使用MLP擬合數(shù)據(jù)mlp.fit(X_train,y_train)# 打印模型得分print('模型得分:{:.2f}'.format(mlp.score(X_test,y_test)))# 書上模型得分是0.24, 我咋有0.93分呢?
模型得分:0.93c:\users\huawei\appdata\local\programs\python\python36\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py:566: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (400) reached and the optimization hasn't converged yet.% self.max_iter, ConvergenceWarning)
# 使用MinMaxScaler進行數(shù)據(jù)預處理from sklearn.preprocessing import MinMaxScalerscaler=MinMaxScaler()scaler.fit(X_train)X_train_pp=scaler.transform(X_train)X_test_pp=scaler.transform(X_test)# 重新訓練模型mlp.fit(X_train_pp,y_train)# 打印模型分數(shù)print('數(shù)據(jù)預處理后的模型得分:{:.2f}'.format(mlp.score(X_test_pp,y_test)))
數(shù)據(jù)預處理后的模型得分:1.00
總結
以上是生活随笔為你收集整理的深入浅出python机器学习_9.1.5_通过数据预处理提高模型的准确率_MinMaxScaler的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 报错: MLPClassifier:Co
- 下一篇: CSDN markdown中实现首行缩进