交叉验证之sklearn.model_selection.GridSearchCV

from sklearn.model_selection import GridSearchCV
tree_param_grid={'min_samples_split':list((3,6,9)),'n_estimators':list((10,50,100))}#对这3*3个参数组合的结果进行比较
grid=GridSearchCV(RandomForestRegressor(),param_grid=tree_param_grid,cv=5)
grid.fit(data_train,target_train)
grid.best_score_#成员变量,输出最好的结果
Out[45]:0.80685458833050794
grid.best_params_#成员变量,输出最好的结果对应的参数
Out[46]:{'min_samples_split': 3, 'n_estimators': 100}

sklearn.model_selection.GridSearchCV(estimator,
param_grid,
scoring=None,
fit_params=None,
n_jobs=None,
iid=’warn’,
refit=True,
cv=’warn’,
verbose=0,
pre_dispatch=‘2*n_jobs’,
error_score=’raise-deprecating’,
return_train_score=’warn’)

只介绍重要的几个参数:
estimator : estimator object
This is assumed to implement the scikit-learn estimator interface. Either estimator needs to provide a score function, or scoring must be passed.
要进行参数选择的模型

param_grid : dict or list of dictionaries
A single string (see The scoring parameter: defining model evaluation rules) or a callable (see Defining your scoring strategy from metric functions) to evaluate the predictions on the test set.
要进行评价的模型参数,用字典表示

cv : int, cross-validation generator or an iterable, optional
Determines the cross-validation splitting strategy. Possible inputs for cv are:
•None, to use the default 3-fold cross validation,
•integer, to specify the number of folds in a (Stratified)KFold,
•An object to be used as a cross-validation generator.
•An iterable yielding train, test splits.
交叉验证的交叉数。

推荐阅读:https://www.cnblogs.com/mdevelopment/p/9634629.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值