sklearn library accuracy_score error

Asked

Viewed 85 times

-1

from sklearn.svm import LinearSVC
from sklearn.metrics import accuracy_score
# retorna 1 se houver mais de 1 número 1
treino_x = [[1,0,1],[1,1,0],[0,0,1],[0,1,1]]
teste_x =[[1,0,0],[1,0,0],[0,0,1],[1,1,1]]
teste_y = np.array([0,0,0,1])
treino_y = np.array([1,1,0,1])

modelo = LinearSVC()
modelo.fit(treino_x,treino_y)
predict = modelo.predict(teste_x)
accuracy_score(teste_y,teste_x)

I tried to train this model, but retouche:

Valueerror: Classification Metrics can’t Handle a mix of Binary and multilabel-Indicator targets Could someone help me? D

2 answers

0


In doing accuracy_score(teste_y,teste_x), you are comparing the expected output (teste_y) with the entry of the model (teste_x).

It is right to compare the expected output with the model response:

accuracy_score(teste_y, predict)
  • 1

    truth! Thank you for helping me, I am a little new in this world, but blood in the eyes and we will fix it there :D

0

In machine learning algorithms there are the input data, which are usually stored in the variable X, as X_train and X_test and variables storing the labels referring to the input data, usually stored in the variable y, as y_train and y_test.

As Alexciuffa mentioned, the method accuracy_score has as parameters the label of the correct data, and the label of the data that its model predicted.

The right thing would be accuracy_score(teste_y, predict)

Another observation is that all models in the Scikit-Learn library have a method for computing average accuracy without the need to import another module.

In the case of LinearSVC, there is the method score, which plays the same role as accuracy_score, receiving test data and test labels.

The use in your code would be as follows:

modelo.score(teste_x, teste_y)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.