我试图使用scoring
参数GridSearchCV
中的参数log_loss
来调整此多类(6类)分类器。我不明白如何给它一个label
参数。即使我给它sklearn.metrics.log_loss
,它会改变交叉验证的每个迭代,所以我不知道如何给它labels
参数?如何在Scikit-Learn(sklearn)中使用`GridSearchCV`中的`log_loss`和多类标签?
我使用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.
UPDATE : 只需使用这使基于基于@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'。还可以看一下http://scikit-learn.org/stable/modules/model_evaluation.html#multilabel-ranking-metrics –