python 參數選擇 基於非常規metric

#調參通過網格搜索完成
from sklearn.datasets import make_hastie_10_2
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import make_scorer
from sklearn.metrics import recall_score,r2_score
from sklearn.ensemble import GradientBoostingRegressor

X=data[feature].values
y=data['Label'].values

# The scorers can be either be one of the predefined metric strings or a scorer
# callable, like the one returned by make_scorer
scoring = {'Mse': make_scorer(mean_squared_error), 'r2': make_scorer(r2_score)}

# Setting refit='AUC', refits an estimator on the whole dataset with the
# parameter setting that has the best cross-validated AUC score.
# That estimator is made available at ``gs.best_estimator_`` along with
# parameters like ``gs.best_score_``, ``gs.best_params_`` and
# ``gs.best_index_``
gs = GridSearchCV(GradientBoostingRegressor(random_state=42),
                  param_grid={'min_samples_split': range(10, 100, 5)},
                  scoring=scoring, cv=5, refit='r2', return_train_score=True)
gs.fit(X, y)
results = gs.cv_results_

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章