您当前的位置: 首页 >  ar

Better Bench

暂无认证

  • 2浏览

    0关注

    695博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【机器学习】解决机器学习中OneVsRestClassifier的网格调参Invalid parameter max_depth for estimator OneVsRestClassifier

Better Bench 发布时间:2021-03-06 21:25:22 ,浏览量:2

简单模型网格调参
from xgboost import XGBClassifier
from sklearn.multiclass import OneVsRestClassifier
from sklearn.model_selection import train_test_split,GridSearchCV
param_test1 = {'max_depth':range(3,10,2),'min_child_weight':range(1,6,2)}

model = XGBClassifier(eval_metric= 'mlogloss',
                                        use_label_encoder=False,
                                        learning_rate =0.1,
                                        n_estimators=100,
                                        gamma=0,
                                        subsample=0.8,
                                        colsample_bytree=0.8,
                                        nthread=4,
                                        scale_pos_weight=1,
                                        seed=27,
                                        verbose=True)
gsearch1 = GridSearchCV(model,param_grid = param_test1,scoring='roc_auc',n_jobs=20, cv=5,verbose=2)
gsearch1.fit(X_train, y_train)
print("最佳参数\n",gsearch1.best_params_)
print("最佳得分",gsearch1.best_score_)
使用OneVsRestClassifier的调参

需要在每个参数面前加上estimator__

param_test1 = {'estimator__max_depth':range(3,10,2),'estimator__min_child_weight':range(1,6,2)}

model = OneVsRestClassifier(XGBClassifier(eval_metric= 'mlogloss',
                                        use_label_encoder=False,
                                        learning_rate =0.1,
                                        n_estimators=100,
                                        gamma=0,
                                        subsample=0.8,
                                        colsample_bytree=0.8,
                                        nthread=4,
                                        scale_pos_weight=1,
                                        seed=27,
                                        verbose=True))
    gsearch1 = GridSearchCV(model,param_grid = param_test1,scoring='roc_auc',n_jobs=20, cv=5,verbose=2)
    gsearch1.fit(X_train, y_train)
print("最佳参数\n",gsearch1.best_params_)
print("最佳得分",gsearch1.best_score_)
关注
打赏
1665674626
查看更多评论
立即登录/注册

微信扫码登录

0.0379s