0

I have a dataset where my target variable is a number between 1 and 8. Now I am going to implement Cubic SVM.

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

from sklearn.svm import SVC

model1 = SVC(kernel='poly', degree=3)
model1.fit(X_train, y_train)

y_prob = model1.predict(X_test)
y_true = np.argmax(y_prob, axis=0)

auc = roc_auc_score(y_test, y_true, multi_class='ovr')

Now to get AUC, the following error is observed:

TypeError: Singleton array array(1) cannot be considered a valid collection.

How to solve this error?

3
  • AUC works with probabilities, not with hard classes, so you should use y_prob and not y_true. Commented May 25, 2024 at 16:58
  • y_prob = model1.predict(X_test) is y_prob and it use in roc_auc_score ,my dear ! Commented May 25, 2024 at 17:02
  • No you are not; you are using y_true = np.argmax(y_prob, axis=0) instead - please look again at your code! Commented May 26, 2024 at 21:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.