上接(1)
完成了数据预处理之后进行回归器的学习:
if self.model_name == "xgboost":
clf = XGBRegressor()
if self.find_best_param:
test_params = {
'max_depth': [2,3, 4, 5, 6],
'learning_rate': [0.25,0.5,0.1, 0.3],
'n_estimators': [10,25,50, 100, 200]
}
mean_squared_error_scorer = make_scorer(score_func=mean_squared_error, greater_is_better=False)
gs = GridSearchCV(estimator=clf, param_grid=test_params, cv=4, verbose=2,
scoring=mean_squared_error_scorer, n_jobs=2)
gs.fit(self.train_X, self.train_y)
print('======xgboost==== Best Results ================')
print('best params: {}, best score: {}'.format(gs.best_params_, gs.best_score_))
print('=============== End ================')
best_params = gs.best_params_
with open