前提・実現したいこと
Pythonで機械学習を勉強しています。
ランダムフォレストを実装してみたのですが
エラーが出てしまって解決できません。
いまやろうとしていることは
1つの目的変数と51の説明変数での回帰モデルの構築です。
(それぞれ960サンプル)
どこがうまくいかない原因なのか
教えていただけると嬉しいです。
発生している問題・エラーメッセージ
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-15-1476b7f18e44> in <module>() 1 print('MSE train: %.3f, test: %.3%' % (mean_squared_error(y40_train, y40_train_pred), ----> 2 mean_squared_error(y40_test, y40_test_pred))) 3 print('R^2 train: %.3f, test: %.3%' % (r2_score(y40_train, y40_train_pred), 4 r2_score(y40_test, y40_test_pred))) TypeError: not all arguments converted during string formatting
該当のソースコード
python
1 2from sklearn.cross_validation import train_test_split 3x40,y40 = df.drop('XMEAS40', axis=1), df40 4x40_train, x40_test, y40_train, y40_test = train_test_split(x40, y40, test_size = 0.3, random_state = 42) 5 6from sklearn.ensemble import RandomForestRegressor 7from sklearn.metrics import mean_squared_error 8from sklearn.metrics import r2_score 9 10forest = RandomForestRegressor(n_estimators = 1000, 11 criterion = 'mse', 12 random_state = 1, 13 n_jobs = -1) 14forest.fit(x40_train, y40_train) 15y40_train_pred = forest.predict(x40_train) 16y40_test_pred = forest.predict(x40_test) 17 18print('MSE train: %.3f, test: %.3%' % (mean_squared_error(y40_train, y40_train_pred), 19 mean_squared_error(y40_test, y40_test_pred))) 20print('R^2 train: %.3f, test: %.3%' % (r2_score(y40_train, y40_train_pred), 21 r2_score(y40_test, y40_test_pred))) 22 23 24### 補足情報(FW/ツールのバージョンなど) 25 26data set: Tennessee Eastman process, 正常時データ 27python3
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。