【发布时间】:2020-03-27 07:51:07
【问题描述】:
我如何使用下面的代码来执行简单的交叉验证和 K 折交叉验证
from sklearn.model_selection import GridSearchCV
import xgboost as xgb
import numpy as np
# our hyperparameters to choose from
learning_rate = [0.0001, 0.001, 0.01, 0.1, 0.2]
n_estimators = [30, 50, 100, 150, 200]
param_grid = dict(learning_rate = learning_rate, n_estimators = n_estimators)
xgb_model = xgb.XGBClassifier(random_state=42, n_jobs = -1)
clf = GridSearchCV(xgb_model, param_grid, scoring = 'roc_auc', cv=3, return_train_score=True)
sc = clf.fit(X_train, y_train)
# getting all the results
scores = clf.cv_results_
# getting train scores and cross validation scores
train_score = scores['mean_train_score']
cv_score = scores['mean_test_score']
【问题讨论】:
-
什么是“简单交叉验证”?
X_cv是什么? -
简单的交叉验证意味着我们在 X_train 上训练我们的模型并在 X_cv 上获得结果(虽然是用于交叉验证的数据矩阵),用于不同的参数集。
标签: python machine-learning scikit-learn grid-search