質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
XGBoost

XGBoostは、アンサンブル学習と決定木を組み合わせた手法です。弱学習器の構築時に、以前構築された弱学習器の結果を用いて弱学習器を構築。高度な汎化能力を持ち、勾配ブースティングとも呼ばれています。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

0回答

1241閲覧

XGBRegressorやGradientBoostingRegressorでMSEが計れません。

rink

総合スコア80

XGBoost

XGBoostは、アンサンブル学習と決定木を組み合わせた手法です。弱学習器の構築時に、以前構築された弱学習器の結果を用いて弱学習器を構築。高度な汎化能力を持ち、勾配ブースティングとも呼ばれています。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2021/12/25 20:20

編集2021/12/27 02:01

題にもあるように、XGBRegressorやGradientBoostingRegressorを使って、MSEが図れないという問題に直面しています。

rmseを返すメソッドは以下のようになっています。

python

1kfolds = KFold(n_splits = 10, shuffle = True, random_state = 42) 2 3def cv_rmse(model, X = X): 4 rmse = np.sqrt(-cross_val_score(model, X, y, scoring = "neg_mean_squared_error", cv = kfolds)) 5 return rmse

また、それぞれのRegressorの定義は、以下のようになります。

python

1alphas_alt = [14.5, 14.6, 14.7, 14.8, 14.9, 15, 15.1, 15.2, 15.3, 15.4, 15.5] 2alphas2 = [5e-05, 0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007, 0.0008] 3e_alphas = [0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007] 4e_l1ratio = [0.8, 0.85, 0.9, 0.95, 0.99, 1] 5 6ridge = make_pipeline(RobustScaler(), RidgeCV(alphas = (0.1, 10, 15), cv = kfolds)) 7lasso = make_pipeline(RobustScaler(), LassoCV(max_iter = 1e7, alphas = alphas2, random_state = 42, cv = kfolds)) 8elasticnet = make_pipeline(RobustScaler(), ElasticNetCV(max_iter = 1e7, alphas = e_alphas, cv = kfolds, l1_ratio = e_l1ratio)) 9svr = make_pipeline(RobustScaler(), SVR(C = 20, epsilon = 0.008, gamma = 0.0003)) 10lightgbm = LGBMRegressor(objective = 'regression', 11 num_leaves = 4, 12 learning_rate = 0.01, 13 n_estimators = 5000, 14 max_bin = 200, 15 bagging_fraction = 0.75, 16 bagging_freq = 5, 17 bagging_seed = 7, 18 feature_fraction = 0.2, 19 feature_fraction_seed = 7, 20 verbose = -1) 21xgboost = xg.XGBRegressor(learning_rate=0.01,n_estimators=3460, 22 max_depth=3, min_child_weight=0, 23 gamma=0, subsample=0.7, 24 colsample_bytree=0.7, 25 objective='reg:linear', nthread=-1, 26 scale_pos_weight=1, seed=27, 27 reg_alpha=0.00006) 28gbr = GradientBoostingRegressor(n_estimators = 3000, 29 learning_rate = 0.05, 30 max_depth = 4, 31 max_features = 'sqrt', 32 min_samples_leaf = 15, 33 min_samples_split = 10, 34 loss = 'huber', 35 random_state = 42)

これらを、以下のようにしてMSEを図ろうとしています。

python

1score = cv_rmse(ridge) 2print("Ridge: {:.4f} ({:.4f})\n".format(score.mean(), score.std())) 3 4score = cv_rmse(lasso) 5print("Lasso: {:.4f} ({:.4f})\n".format(score.mean(), score.std())) 6 7score = cv_rmse(elasticnet) 8print("elastic net: {:.4f} ({:.4f})\n".format(score.mean(), score.std())) 9 10score = cv_rmse(svr) 11print("SVR: {:.4f} ({:.4f})\n".format(score.mean(), score.std())) 12 13score = cv_rmse(lightgbm) 14print("lightgbm: {:.4f} ({:.4f})\n".format(score.mean(), score.std())) 15 16score = cv_rmse(gbr) 17print("gradient_boosting_regressor: {:.4f} ({:.4f})".format(score.mean(), score.std())) 18 19score = cv_rmse(xgboost) 20print("xgboost: {:.4f} ({:.4f})\n".format(score.mean(), score.std()))

ですが、gbrまでの5つは動くのですが、下二つのgradientboostingregressorとxgboostは、出力が

plain

1[nan nan nan nan nan nan nan nan nan nan]

となってしまいます。何が原因でしょうか。どなたかわかる方、ご教示いただけますと幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問