如何知道0级有多少,1级有多少?
Posted
技术标签:
【中文标题】如何知道0级有多少,1级有多少?【英文标题】:How to know how many is class 0 and how many is class 1? 【发布时间】:2019-05-12 13:59:33 【问题描述】:我有一个代码可以提供 SVM 的准确性,但我想知道 0 类和 1 类有多少。
这里是代码
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score
clf = SVC(C=10000.0, kernel='rbf')
t0 = time()
clf.fit(features_train, labels_train)
print "training_time:", round(time()-t0, 3), "s"
t0 = time()
pred = clf.predict(features_test)
print "prediction time:", round(time()-t0, 3), "s"
acc = accuracy_score(pred, labels_test)
print acc
我试过下面这段代码,但没有成功...
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score
clf = SVC(C=10000.0, kernel='rbf', probability=True)
t0 = time()
clf.fit(features_train, labels_train)
print "training_time:", round(time()-t0, 3), "s"
t0 = time()
pred = clf.predict(features_test)
class = clf.predict_proba(features_test)
print sum(class)
print "prediction time:", round(time()-t0, 3), "s"
acc = accuracy_score(pred, labels_test)
print acc
我错过了什么?太棒了!
【问题讨论】:
【参考方案1】:您可以创建混淆矩阵来理解您的预测
from sklearn.metrics import confusion_matrix
confusion_matrix(labels_test, pred)
【讨论】:
以上是关于如何知道0级有多少,1级有多少?的主要内容,如果未能解决你的问题,请参考以下文章
强制 QObject 作为 QWidget 的父级有啥后果?