深入浅出python机器学习_9.1.5_通过数据预处理提高模型的准确率_MinMaxScaler
生活随笔
收集整理的這篇文章主要介紹了
深入浅出python机器学习_9.1.5_通过数据预处理提高模型的准确率_MinMaxScaler
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
# 導(dǎo)入紅酒數(shù)據(jù)集from sklearn.datasets import load_wine# 導(dǎo)入MLP神經(jīng)網(wǎng)絡(luò)from sklearn.neural_network import MLPClassifier# 導(dǎo)入數(shù)據(jù)集拆分工具from sklearn.model_selection import train_test_split# 建立訓(xùn)練集個(gè)測(cè)試集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)
# 設(shè)定MLP神經(jīng)網(wǎng)絡(luò)的參數(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)))# 書(shū)上模型得分是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進(jìn)行數(shù)據(jù)預(yù)處理from sklearn.preprocessing import MinMaxScalerscaler=MinMaxScaler()scaler.fit(X_train)X_train_pp=scaler.transform(X_train)X_test_pp=scaler.transform(X_test)# 重新訓(xùn)練模型mlp.fit(X_train_pp,y_train)# 打印模型分?jǐn)?shù)print('數(shù)據(jù)預(yù)處理后的模型得分:{:.2f}'.format(mlp.score(X_test_pp,y_test)))
數(shù)據(jù)預(yù)處理后的模型得分:1.00
總結(jié)
以上是生活随笔為你收集整理的深入浅出python机器学习_9.1.5_通过数据预处理提高模型的准确率_MinMaxScaler的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 报错: MLPClassifier:Co
- 下一篇: python sklearn.decom