1

I made a SVC but I am confused in interpreting the results for the probability. Lets say there are 3 categories cat, dog, and fish and I want to know the probability which it can be of each one so I used .predict to find the prediction and .predict_proba but it does not come out correct for small samples.

from sklearn import svm
X = [[1,2,3], [2,3,4], [1,1,3], [2,3,5], [3,4,6], [2,3,4],[1,2,3]]
y = ['cat', 'dog', 'cat','dog','fish','dog','cat']
clf =svm.SVC(probability=True)
clf.fit(X, y)
a=clf.decision_function([3,4,6])
b=clf.predict_proba([3,4,6])
c=clf.score(X, y)

print clf.classes_
print 'accuracy', c
print 'Fish prediction'
print clf.predict([3,4,6])
print 'decision function', a
print  'predict', b

If I predict something with low amount of samples like fish it is accurate but can someone explain why the prediction probability is so low: 0.027. (I know it is using Platt Scaling but why was dog not selected at a probability of 0.71) Is there way to obtain the probability which the SVM predicts that the results are fish?

['cat' 'dog' 'fish']
accuracy 1.0
Fish prediction
['fish']
decision function [[-0.25639624 -0.85413901 -0.25966687]]
predict [[ 0.26194797  0.71056399  0.02748803]]

Lets say I want to predict cat:

#predict cat
d=clf.decision_function([1,2,3])
e=clf.predict_proba([1,2,3])
print 'Cat prediction'
print clf.predict([1,2,3])
print 'decision function', d
print  'predict', e

It printed out the correct probability of 0.61

Cat prediction
['cat']
decision function [[ 0.99964652  0.99999999  0.54610562]]
predict [[ 0.61104793  0.19764548  0.19130659]]

Also I think I am using the score wrong since it is tested against itself and yields the value of 1 meaning that it is 100% accurate. How do I correctly use score?

Community
  • 1
  • 1
user3084006
  • 5,344
  • 11
  • 32
  • 41
  • 1
    In the multiclass case, what `SVC.predict_proba` does is actually an extended version of Platt scaling from [this paper](http://www.csie.ntu.edu.tw/~cjlin/papers/svmprob/svmprob.pdf). `clf.probA_` and `clf.probB_` contain the relevant parameters. I'm sorry to leave it at this, but Platt-scaled SVMs are just about the hardest to interpret probability models out there (and the slowest to train). – Fred Foo Jan 27 '14 at 10:14
  • @larsmans Is there a better way to return a probability this case? – user3084006 Jan 27 '14 at 10:21
  • Use `LogisticRegression`? If you really need a non-linear model, you can look at the module `sklearn.kernel_approximation`; see also [this blog post](http://peekaboo-vision.blogspot.nl/2012/12/kernel-approximations-for-efficient.html) by @AndreasMueller. – Fred Foo Jan 27 '14 at 10:27
  • @larsmans isn't that the same as switching to a linear kernel? The first thing I tried was `linearSVC``\ but it gave me the wrong predictions. `clf.predict([3,4,6])` gave me dog instead of fish. The reason I am trying this is to see how it handles uncommon data points. I know my data set is also not large enough for SVM – user3084006 Jan 27 '14 at 11:00
  • 1
    `LinearSVC` and LogReg are differently parametrized than `SVC`. You haven't optimized the parameter settings, you haven't normalized the data, and you're testing on a single sample, so you really can't draw the conclusion that it gives wrong predictions. – Fred Foo Jan 27 '14 at 12:01

0 Answers0