Why does GridSearchCV on an SVC in scikit-learn produce different probabilities given identical inputs?

Jeff

For some reason GridSearchCV with an svc is producing slightly probability results given the same inputs. On the sample I've posted below, the difference is small, but I've had it be much larger on other problems. Shouldn't the GridSearch produce the same results given the same inputs each time?

See also a previous question by another user, predict_proba or decision_function as estimator "confidence" which addressed the same issue with Logistic Regression, but that turned out to be a bug -- perhaps this is too? Or does the GridSearchCV use a random seed? The difference isn't too bad in this demo problem, but I have other more complicated problems where the probability difference is enough to predict the other side of a binary state.

from sklearn import svm, grid_search, datasets
iris = datasets.load_iris()
parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}
svr = svm.SVC(probability=True)
clf = grid_search.GridSearchCV(svr, parameters)
clf.fit(iris.data, iris.target)
clf.predict_proba(iris.data)

array([[  9.75883684e-01,   1.55259588e-02,   8.59035759e-03],
       [  9.61565216e-01,   2.74888948e-02,   1.09458891e-02],
       [  9.74605121e-01,   1.68928925e-02,   8.50198656e-03],
       [  9.58212635e-01,   2.97479036e-02,   1.20394616e-02],
....

and when I run the exact same code again, I get:

array([[  9.76047242e-01,   1.54138902e-02,   8.53886802e-03],
       [  9.61893348e-01,   2.72510317e-02,   1.08556202e-02],
       [  9.74780630e-01,   1.67675046e-02,   8.45186573e-03],
       [  9.58586150e-01,   2.94842759e-02,   1.19295743e-02],'

and I can run again and again and get more different results.

Is this normal for GridSearchCV on a svc, or am I doing something wrong, or is this a bug?

I am using scikit-learn .14.1.

Thank you.

Raff.Edward

SVMs do not support probabilities. A trick to resolve this is to essentially perform logistic regression on the margin distance of each data point to the SVM decision boundary. If we did this directly, there may be some issues from the fact that all support vectors will have a distance of +- 1. To avoid this bias, 3 folds are created and a CV like procedure done to get margin values for 1/3 of the data at a time (trained on the other 2/3 of the data). Then the logistic regression is done on those values, and the SVM retrained on the whole data set. This is called Platt Scaling. The CV part is where the randomness comes in.

I've got a post that has a few 2D examples of it and some more explanation.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does GridSearchCV on an SVC in scikit-learn produce different probabilities given identical inputs?

From Dev

Why does not GridSearchCV give best score ? - Scikit Learn

From Dev

Why does Python produce different sets from identical input?

From Dev

Why these syntactically identical functions produce different results?

From Dev

Why these syntactically identical functions produce different results?

From Dev

scikit learn GridSearchCV on KNeighbors

From Dev

GridSearchCV on LogisticRegression in scikit-learn

From Dev

Does scikit learn include a Naive Bayes classifier with continuous inputs?

From Dev

Why do two seemingly identical variables produce two different results?

From Dev

Python Scikit-learn Perceptron Output Probabilities

From Dev

scikit-learn: building a learning curve with SVC

From Dev

Using Smote with Gridsearchcv in Scikit-learn

From Dev

Converting LinearSVC's decision function to probabilities (Scikit learn python )

From Dev

Scikit-learn Ridge classifier: extracting class probabilities

From Dev

Scikit-Learn: How to retrieve prediction probabilities for a KFold CV?

From Dev

Confusing probabilities of the predict_proba of scikit-learn's svm

From Dev

Scikit-learn Ridge classifier: extracting class probabilities

From Dev

Scikit-Learn: How to retrieve prediction probabilities for a KFold CV?

From Dev

scikit-learn - multinomial logistic regression with probabilities as a target variable

From Dev

Why does different scrypt implementation produce different results?

From Dev

Why does scikit-learn cause core dumped?

From Dev

Why does scikit learn return log-density?

From Dev

scikit learn svc coef0 parameter range

From Dev

What is the difference between SVC and SVM in scikit-learn?

From Dev

Under what parameters are SVC and LinearSVC in scikit-learn equivalent?

From Dev

Why does one of two identical VS2015 projects produce error C4995?

From Dev

Why does an operation on two identical lists end up in different results?

From Dev

Why does Excel treat these two identical looking cells as different?

From Dev

Why does LINQ GroupBy produce different results when preceded by ToArray()?

Related Related

  1. 1

    Why does GridSearchCV on an SVC in scikit-learn produce different probabilities given identical inputs?

  2. 2

    Why does not GridSearchCV give best score ? - Scikit Learn

  3. 3

    Why does Python produce different sets from identical input?

  4. 4

    Why these syntactically identical functions produce different results?

  5. 5

    Why these syntactically identical functions produce different results?

  6. 6

    scikit learn GridSearchCV on KNeighbors

  7. 7

    GridSearchCV on LogisticRegression in scikit-learn

  8. 8

    Does scikit learn include a Naive Bayes classifier with continuous inputs?

  9. 9

    Why do two seemingly identical variables produce two different results?

  10. 10

    Python Scikit-learn Perceptron Output Probabilities

  11. 11

    scikit-learn: building a learning curve with SVC

  12. 12

    Using Smote with Gridsearchcv in Scikit-learn

  13. 13

    Converting LinearSVC's decision function to probabilities (Scikit learn python )

  14. 14

    Scikit-learn Ridge classifier: extracting class probabilities

  15. 15

    Scikit-Learn: How to retrieve prediction probabilities for a KFold CV?

  16. 16

    Confusing probabilities of the predict_proba of scikit-learn's svm

  17. 17

    Scikit-learn Ridge classifier: extracting class probabilities

  18. 18

    Scikit-Learn: How to retrieve prediction probabilities for a KFold CV?

  19. 19

    scikit-learn - multinomial logistic regression with probabilities as a target variable

  20. 20

    Why does different scrypt implementation produce different results?

  21. 21

    Why does scikit-learn cause core dumped?

  22. 22

    Why does scikit learn return log-density?

  23. 23

    scikit learn svc coef0 parameter range

  24. 24

    What is the difference between SVC and SVM in scikit-learn?

  25. 25

    Under what parameters are SVC and LinearSVC in scikit-learn equivalent?

  26. 26

    Why does one of two identical VS2015 projects produce error C4995?

  27. 27

    Why does an operation on two identical lists end up in different results?

  28. 28

    Why does Excel treat these two identical looking cells as different?

  29. 29

    Why does LINQ GroupBy produce different results when preceded by ToArray()?

HotTag

Archive