使用randomizedsearchcv给出的最佳估计量进行预测时会得到奇怪的结果

时间:2019-01-07 16:40:51

标签: python xgboost predict grid-search

我使用xgbclassifier进行预测。尽管我的最佳成绩(使用“ auc”评分)平均为0.77,但是当我使用最佳估算器进行预测时,效果却非常差,仅为0.55。那我的代码怎么了?

[clf = xgb.XGBClassifier(objective='binary:logistic', booster='gbtree',
                        n_jobs=4,gamma=0.1,  max_delta_step=0, 
                        colsample_bylevel=1,
                        reg_alpha=0, reg_lambda=2, scale_pos_weight=1, base_score=0.5, random_state=1 )

param_dist = {
        'n_estimators': \[100,120\],
        'max_depth':\[3,4,5\],
        'learning_rate':np.linspace(0.01,0.02,2),
        'subsample':np.linspace(0.6,0.8,5),
        'colsample_bytree':np.linspace(0.6,0.7,6),
        'min_child_weight':\[1,2\],
        'scale_pos_weight':\[1,2,3,4\],

        }
fit_params = {
              'eval_metric': 'auc',
              'early_stopping_rounds': 10,
              'eval_set':\[(X_test, y_test)\] }

rs_clf = RandomizedSearchCV(clf, param_dist, n_iter=20,
                            n_jobs=1, verbose=2, cv=4,
                            scoring='roc_auc', refit=True,random_state=42)

rs_clf.fit(X_train,y_train,**fit_params)

y_train_pred=rs_clf.predict(X_train)
y_test_pred=rs_clf.predict(X_test)

fpr1, tpr1, thresholds1 = roc_curve(y_train, y_train_pred)
roc_auc1 = auc(fpr1, tpr1)
roc_auc1

fpr2, tpr2, thresholds2 = roc_curve(y_test, y_test_pred)
roc_auc2 = auc(fpr2, tpr2)
roc_auc2][1]

0 个答案:

没有答案