【发布时间】:2017-09-08 16:27:52
【问题描述】:
我正在尝试使用GridSearchCV 的scoring 参数中的log_loss 参数来调整这个多类(6 类)分类器。我不明白如何给它一个label 参数。即使我给了它sklearn.metrics.log_loss,它也会随着交叉验证中的每次迭代而改变,所以我不明白如何给它labels 参数?
我正在使用Python v3.6 和Scikit-Learn v0.18.1
如何使用GridSearchCV 和log_loss 进行多类模型调优?
我的班级代表:
1 31
2 18
3 28
4 19
5 17
6 22
Name: encoding, dtype: int64
我的代码:
param_test = {"criterion": ["friedman_mse", "mse", "mae"]}
gsearch_gbc = GridSearchCV(estimator = GradientBoostingClassifier(n_estimators=10),
param_grid = param_test, scoring="log_loss", n_jobs=1, iid=False, cv=cv_indices)
gsearch_gbc.fit(df_attr, Se_targets)
这是错误的结尾,完整的在这里https://pastebin.com/1CshpEBN:
ValueError: y_true contains only one label (1). Please provide the true labels explicitly through the labels argument.
更新: 只需使用它来制作基于@Grr 的得分手
log_loss_build = lambda y: metrics.make_scorer(metrics.log_loss, greater_is_better=False, needs_proba=True, labels=sorted(np.unique(y)))
【问题讨论】:
-
在这里打印您的
Se_targets。还有看看scikit-learn.org/stable/modules/… -
@O.rka:标签=排序(np.unique(y))。这里 y 包含训练集中条目的标签,对吧?或者它是否包含数据集中所有条目的标签?
标签: python optimization machine-learning scikit-learn grid-search