预测概率 [英] Predicting probability
问题描述
尝试使用sklearn
中的SVC
进行分类问题.给定一堆数据,并且信息告诉我某个学科是否在某个班级中,我希望能够给出一个新的未知学科在班级中的可能性.
Trying to use SVC
from sklearn
to do a classification problem. Given a bunch of data, and information telling me whether some subject is in a certain class or not, I want to be able to give a probability that a new, unknown subject is in a class.
我只有2个课,所以问题是二进制的.这是我的代码和一些错误
I only have 2 classes, so the problem is binary. Here is my code and some of my errors
from sklearn.svm import SVC
clf=SVC()
clf=clf.fit(X,Y)
SVC(probability=True)
print clf.predict_proba(W) #Error is here
但是它返回以下错误:
NotImplementedError: probability estimates must be enabled to use this method
我该如何解决?
推荐答案
您必须使用probability=True
from sklearn.svm import SVC
clf=SVC(probability=True)
clf.fit(X,Y)
print clf.predict_proba(W) #No error
您的代码使用概率估计值创建了一个SVC并将其丢弃(因为您没有将其存储在任何变量中),并使用了存储在clf中的先前的SVC(无概率)
Your code creates a SVC with probability estimates and discards it (as you do not store it in any variable) and use some previous SVC stored in clf (without probability)
这篇关于预测概率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!