Churning prediction probabilities scibit-learn svm

My goal is to draw a PR curve by sorting the likelihood of each sample for a specific class. However, I found that the svm predict_proba () generated probabilities have two different behaviors when I use two different standard datasets: aperture and numbers.

The first case is evaluated in the "iris" case with the python code below, and it works reasonably that the class gets the highest probability.

D = datasets.load_iris()
clf = SVC(kernel=chi2_kernel, probability=True).fit(D.data, D.target)
output_predict = clf.predict(D.data)
output_proba = clf.predict_proba(D.data)
output_decision_function = clf.decision_function(D.data)
output_my = proba_to_class(output_proba, clf.classes_)

print D.data.shape, D.target.shape
print "target:", D.target[:2]
print "class:", clf.classes_
print "output_predict:", output_predict[:2]
print "output_proba:", output_proba[:2]

      

Then it issues the output as shown below. Apparently, the highest probability of each sample corresponds to the prediction outputs (): 0.97181088 for sample No. 1 and 0.96961523 for sample No. 2.

(150, 4) (150,)
target: [0 0]
class: [0 1 2]
output_predict: [0 0]
output_proba: [[ 0.97181088  0.01558693  0.01260218]
[ 0.96961523  0.01702481  0.01335995]]

      

However, when I change the dataset to "numbers" with the following code, the probabilities show the opposite phenomenon, that the least probability of each sample dominates the inferred prediction labels () with a probability of 0.00190932 for sample # 1 and 0.00220549 for sample # 2.

D = datasets.load_digits()

      

Outputs:

(1797, 64) (1797,)
target: [0 1]
class: [0 1 2 3 4 5 6 7 8 9]
output_predict: [0 1]
output_proba: [[ 0.00190932  0.11212957  0.1092459   0.11262532      0.11150733  0.11208733
0.11156622  0.11043403  0.10747514  0.11101985]
[ 0.10991574  0.00220549  0.10944998  0.11288081  0.11178518   0.11234661
0.11182221  0.11065663  0.10770783  0.11122952]]

      

I read this post and it leads to a solution to use a linear SVM using the decision function (). However, due to my task, I still need to focus on the chi-squared core for SVM.

Any solutions?

+3


source to share


1 answer







All Articles