python - 如何知道有多少个是0级,有多少个是1级?

标签 python machine-learning scikit-learn svm prediction

我有一个代码可以提供 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

我错过了什么?泰!

最佳答案

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

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

关于python - 如何知道有多少个是0级,有多少个是1级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53726503/

相关文章:

python - 错误 : "can only concatenate tuple (not "list") to tuple"in urls, Django

python - Pandas 计算不同列中的相同值

python - PySpark LogisticRegressionWithLBFGS 导入错误

python - 使用 sklearn 提取 PCA 成分

python - 我可以仅对多个数据类型的 DataFrame 中的数值数据使用 K-Means 吗?

python - 将元素插入到 numpy 数组的开头和结尾

python - Keras:rescale=1./255 与 preprocessing_function=preprocess_input - 使用哪一个?

python - 关键 : tensorflow:Category has no images - validation

python - 为 kmeans scikit 堆叠 3 个变量

pandas - Scikit ROC auc 引发 ValueError : Only one class present in y_true. ROC AUC 分数在这种情况下未定义