可以默认输出类吗?
数据挖掘
分类
预测建模
多标签分类
2022-03-14 22:48:29
2个回答
我认为没有标准的方法可以做到这一点。但是,如果您使用概率模型,则可以将预测概率与每个类别的阈值一起使用,以仅允许您认为足够确定的分类。然后,如果概率最高的类不满足阈值,您可以将其设置为默认类。
我用 sklearn 和 numpy 对其进行了测试,这可能是一种方法:
# Train probabilistic classifier
clf.fit(X_train, y_train)
# Get probabilities
probas = clf.predict_proba(X_test)
# Get the class with highest probability
highest_proba_class = np.argmax(probas, axis=1)
# Set different thresholds per class
thresholds = np.array([0.9, 0.2, 0.5])
# Init our prediction array
predictions = np.zeros_like(highest_proba_class)
# Set a default class to set if we don't reach threshold
default_class = 2
# Loop over predictions
for idx, highest_class in enumerate(highest_proba_class):
# Threshold check if threshold was met, otherwise set default
if probas[idx][highest_class] >= thresholds[highest_class]:
predictions[idx] = highest_class
else:
predictions[idx] = default_class
其它你可能感兴趣的问题
