Why does sklearn.model_selection.GridSearchCV not have a consistent result?

51 views Asked by At

I change the code from https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html a little bit, which looks like this:

from sklearn import svm, datasets
from sklearn.model_selection import GridSearchCV
iris = datasets.load_iris()
parameters = {'kernel':('linear','rbf'), 'C':[10,20, 15,  4]}
svc = svm.SVC()
clf = GridSearchCV(svc, parameters)
clf.fit(iris.data, iris.target)
clf.best_params_

Then the result is:

{'C': 10, 'kernel': 'rbf'}

But if I change the code to:

parameters = {'kernel':('linear','rbf'), 'C':[4, 10,20, 15]}

You can see the only change is the sequence of C list. But the result is:

{'C': 4, 'kernel': 'rbf'}

It looks like GridSearchCV just uses the first parameter combination.

So I have a few questions about this:

  1. In this case, scoring is the default (None), so what function actually uses here? And why the above situation happens?
  2. As far as I know, when we use LatentDirichletAllocation and GridSearchCV, the scoring function is log likelihood even scoring=None. If I understand correctly, then GridSearchCV can automatically pick a scoring function when it combines different models?
0

There are 0 answers