題にもあるように、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]
となってしまいます。何が原因でしょうか。どなたかわかる方、ご教示いただけますと幸いです。
あなたの回答
tips
プレビュー