I am trying to plot ROC and thus calculate false positive and negative rate using the sklearn.metrics.roc_curve function.
roc_data = *somedataframeimport*
X_train, X_test, y_train, y_test = split_vect_trans(roc_data)
After vectorizing and transforming my data with my own function here, I fit a NN with it and make predictions.
nn_roc = OneVsRestClassifier(MLPClassifier())
nn_roc = nn_roc.fit(X_train, y_train)
pred = nn_roc.predict(X_test)
fpr = dict()
tpr = dict()
roc_auc = dict()
for i in range(len(y_score)):
fpr[i], tpr[i], _ = metrics.roc_curve(y_test[:, i], y_score[:, i])
roc_auc[i] = metrics.auc(fpr[i], tpr[i])
Always get the following error message though, when passing the data into the roc_curve function.
5 for i in range(len(y_score)):
----> 6 fpr[i], tpr[i], _ = metrics.roc_curve(y_test[:, i], y_score[:, i])
7 roc_auc[i] = metrics.auc(fpr[i], tpr[i])
TypeError: list indices must be integers, not tuple
I tried adding a line that explicitly converts the input data to an array (suggestion I read on another post for the same error message). This now gives IndexError: too many indices for array as an error message.
y_test_array = np.asarray(y_test)
y_score = np.asarray(pred)
for i in range(len(y_score)):
fpr[i], tpr[i], _ = metrics.roc_curve(y_test[:, i], y_score[:, i])
roc_auc[i] = metrics.auc(fpr[i], tpr[i])