【发布时间】:2022-01-20 02:22:40
【问题描述】:
我已经构建了许多 sklearn 分类器模型来执行多标签分类,我想校准它们的 predict_proba 输出,以便获得置信度分数。我还想使用 sklearn.metrics.recall_score 等指标来评估它们。
我有 4 个标签要预测,真正的标签是多热编码的(例如[0, 1, 1, 1])。结果CalibratedClassifierCV不直接接受我的数据:
clf = tree.DecisionTreeClassifier(max_depth=15)
clf = clf.fit(train_X, train_Y)
calibrated_clf = CalibratedClassifierCV(clf, cv="prefit", method="sigmoid")
calibrated_clf.fit(dev_X, dev_Y)
这会返回一个错误:
ValueError: classes [[0 1]
[0 1]
[0 1]
[0 1]] mismatch with the labels [0 1 2 3] found in the data
因此,我尝试将其包装在OneVsRestClassifier:
clf = OneVsRestClassifier(tree.DecisionTreeClassifier(max_depth=15), n_jobs=4)
clf = clf.fit(train_X, train_Y)
calibrated_clf = CalibratedClassifierCV(clf, cv="prefit", method="sigmoid")
calibrated_clf.fit(dev_X, dev_Y)
请注意,MultiOutputClassifier 和 ClassifierChain 不起作用,即使它们可能更适合我的问题。
它可以工作,但由于its implementation,校准分类器的predict 输出是多类 而不是多标签。有四个类([0 1 2 3]),但如果不需要贴标签,它仍然会预测为0。
通过校准曲线进一步检查,结果发现包裹在校准分类器内的基本估计器根本没有校准。也就是说,(calibrated_clf.calibrated_classifiers_)[0].base_estimator 返回与校准前相同的clf。
我想观察我的(校准的)模型在进行确定性 (predict) 和概率性 (predict_proba) 预测时的表现。我应该如何设计我的模型/将东西包装在其他容器中以获得每个标签的校准概率和可理解的标签预测?
【问题讨论】:
标签: python machine-learning scikit-learn classification