我想要获取每个预测的置信度分数,以显示分类器对其正确性的确定程度。
我需要类似这样的东西:
分类器在其预测上有多确定?
类别 1:81% 的可能性是类别 1
类别 2:10%
类别 3:6%
类别 4:3%
我的代码示例:
features_train, features_test, labels_train, labels_test = cross_validation.train_test_split(main, target, test_size = 0.4)
# Determine amount of time to train
t0 = time()
model = SVC()
#model = SVC(kernel='poly')
#model = GaussianNB()
model.fit(features_train, labels_train)
print 'training time: ', round(time()-t0, 3), 's'
# Determine amount of time to predict
t1 = time()
pred = model.predict(features_test)
print 'predicting time: ', round(time()-t1, 3), 's'
accuracy = accuracy_score(labels_test, pred)
print 'Confusion Matrix: '
print confusion_matrix(labels_test, pred)
# Accuracy in the 0.9333, 9.6667, 1.0 range
print accuracy
model.predict(sub_main)
# Determine amount of time to predict
t1 = time()
pred = model.predict(sub_main)
print 'predicting time: ', round(time()-t1, 3), 's'
print ''
print 'Prediction: '
print pred
我认为我需要使用score()函数,但似乎一直没有正确实现它。我不知道是否使用了正确的函数,但如何获取分类器预测的置信度百分比呢?
classifier.classes_
。但是如果数据集很小,它们就没有意义 :-( 。此外,它们也不能保证与classifier.predict()
匹配 :'( 。文档页面链接 - AneesAhmed777