SKLearn 如何获得 LinearSVC 分类器的决策概率 [英] SKLearn how to get decision probabilities for LinearSVC classifier
问题描述
我正在使用 scikit-learn 的 linearSVC 分类器进行文本挖掘.我将 y 值作为标签 0/1,将 X 值作为文本文档的 TfidfVectorizer.
I am using scikit-learn's linearSVC classifier for text mining. I have the y value as a label 0/1 and the X value as the TfidfVectorizer of the text document.
我使用如下所示的管道
pipeline = Pipeline([
('count_vectorizer', TfidfVectorizer(ngram_range=(1, 2))),
('classifier', LinearSVC())
])
对于预测,我想获得数据点被分类为的置信度分数或概率1 在 (0,1) 范围内
For a prediction, I would like to get the confidence score or probability of a data point being classified as 1 in the range (0,1)
我目前使用决策函数功能
I currently use the decision function feature
pipeline.decision_function(test_X)
然而,它返回似乎表明置信度的正值和负值.我也不太清楚它们的意思.
However it returns positive and negative values that seem to indicate confidence. I am not too sure about what they mean either.
但是,有没有办法获得 0-1 范围内的值?
However, is there a way to get the values in range 0-1?
例如这里是一些数据点的决策函数的输出
For example here is the output of the decision function for some of the data points
-0.40671879072078421,
-0.40671879072078421,
-0.64549376401063352,
-0.40610652684648957,
-0.40610652684648957,
-0.64549376401063352,
-0.64549376401063352,
-0.5468745098794594,
-0.33976011539714374,
0.36781572474117097,
-0.094943829974515004,
0.37728641897721765,
0.2856211778200019,
0.11775493140003235,
0.19387473663623439,
-0.062620918785563556,
-0.17080866610522819,
0.61791016307670399,
0.33631340372946961,
0.87081276844501176,
1.026991628346146,
0.092097790098391641,
-0.3266704728249083,
0.050368652422013376,
-0.046834129250376291,
推荐答案
你不能.但是,您可以将 sklearn.svm.SVC
与 kernel='linear'
和 probability=True
You can't.
However you can use sklearn.svm.SVC
with kernel='linear'
and probability=True
它可能运行的时间更长,但您可以使用 predict_proba
方法从这个分类器中获取概率.
It may run longer, but you can get probabilities from this classifier by using predict_proba
method.
clf=sklearn.svm.SVC(kernel='linear',probability=True)
clf.fit(X,y)
clf.predict_proba(X_test)
这篇关于SKLearn 如何获得 LinearSVC 分类器的决策概率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!