-1

By using GridSearchCV I can obtain clf.cv_results_['params'] and I would like to run over all the possible combinations and printing some probabilities:

for params in zip(clf.cv_results_['params']):
        print(params)
        clf= SVC(params)
        clf.fit(X_train, y_train)
        z_test=clf.predict(X_test)
        print("Probability 1:", prob_error(y_test,z_test))
        print("Probability 2:", average_error(y_test,z_test))

However, in params I obtain this:

({'C': 1000, 'gamma': 1000, 'tol': 2},)

How can I transform this in order to do the fit of the algorithm? Because this code has an error in "clf.fit(X_train, y_train)":

TypeError: must be real number, not tuple
xelact
  • 15
  • 4

1 Answers1

0

Why are you using zip on the clf.cv_results_['params']. Remove that and do it like below:

for params in clf.cv_results_['params']:
        print(params)
        clf= SVC(**params)
        clf.fit(X_train, y_train)
        z_test=clf.predict(X_test)
        print("Probability 1:", prob_error(y_test,z_test))
        print("Probability 2:", average_error(y_test,z_test))

See this for more details:

Vivek Kumar
  • 35,217
  • 8
  • 109
  • 132