关于sklearn.model_selection.GridSearchCV的python实例和说明

>>> from sklearn import svm, datasets
>>> from sklearn.model_selection import GridSearchCV
>>> iris = datasets.load_iris()
>>> parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}
>>> svc = svm.SVC()
>>> clf = GridSearchCV(svc, parameters)
>>> clf.fit(iris.data, iris.target)
GridSearchCV(estimator=SVC(),
             param_grid={'C': [1, 10], 'kernel': ('linear', 'rbf')})
>>> sorted(clf.cv_results_.keys())
['mean_fit_time', 'mean_score_time', 'mean_test_score',...
 'param_C', 'param_kernel', 'params',...
 'rank_test_score', 'split0_test_score',...
 'split2_test_score', ...
 'std_fit_time', 'std_score_time', 'std_test_score']

总结:
grid_search=GridSearchCV(estimator=SVC(),
param_grid={‘C’: [1, 10], ‘kernel’: (‘linear’, ‘rbf’)})
grid_result=classifier.fit(X_train,y_train)

grid_result.best_score_ :成员提供优化过程期间观察到的最好的评分
grid_search.best_params_:描述了已取得最佳结果的参数的组合

best_params_:描述了已取得最佳结果的参数的组合
best_score_:成员提供优化过程期间观察到的最好的评分

且评分的方式可以在GridSearchCV的参数列scoring=……中进行修改,比如scoring=‘neg_log_loss’ (具体参考官网的metric说明)

地址:
https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html#sklearn.model_selection.GridSearchCV
参考:
https://blog.csdn.net/weixin_41988628/article/details/83098130

你可能感兴趣的:(关于sklearn.model_selection.GridSearchCV的python实例和说明)