【问题标题】:How to know how many is class 0 and how many is class 1?如何知道0级有多少,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

我错过了什么?太棒了!

【问题讨论】:

    标签: python machine-learning scikit-learn svm prediction


    【解决方案1】:

    您可以创建混淆矩阵来理解您的预测

    from sklearn.metrics import confusion_matrix
    confusion_matrix(labels_test, pred)
    

    【讨论】:

      猜你喜欢
      • 2010-12-19
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 2017-03-02
      • 2016-11-10
      • 2014-03-01
      • 2015-05-12
      • 1970-01-01
      相关资源
      最近更新 更多