0

Using Python 2.7, I am trying to carry out grid searches for AUC and accuracy scores for a SVC model. I get the error as outlined below.

Attempted to troubleshoot to no avail.

clf = SVC(kernel = 'rbf')
parameter_grid = [
  {'C': [0.1, 1, 10, 50, 100, 400], 
   'gamma': [0.0001, 0.001, 0.01, 0.1, 1, 10]}
]

clf_stand_acc = GridSearchCV(clf, param_grid = parameter_grid)
clf_stand_acc.fit(X_train, y_train) 
y_predict_auc = clf_stand_acc.predict(X_test)


clf_stand_auc = GridSearchCV(clf, param_grid = parameter_grid, scoring = 'roc_auc')
clf_stand_auc.fit(X_train, y_train) 
y_predict_auc = clf_stand_auc.predict(X_test)

print('Test of AUC: ', roc_auc_score(y_test, y_predict_auc))

Expected something like the following output. Test set AUC: 0.9993784757585

Snippet of the actual output below.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-47-ef06600e0bf8> in <module>()
     19 # Generate an auc object with the classifier and grid parameters.
     20 clf_stand_auc = GridSearchCV(clf, param_grid = parameter_grid, scoring = 'roc_auc')
---> 21 clf_stand_auc.fit(X_train, y_train)
     22 y_predict_auc = clf_stand_auc.predict(X_test)
     23 

ValueError: Data is not binary and pos_label is not specified
desertnaut
  • 57,590
  • 26
  • 140
  • 166
db2020
  • 69
  • 8

1 Answers1

0

As this answer goes(possible duplicate): ValueError: Data is not binary and pos_label is not specified

Your y_train, should look like this:

y_train=np.array([0, 1, 0, 0, 1, 1, 1, 1, 1])

I don't know what your y values look like, however this should help you: one hot encode a binary value in numpy