Linearregression score

Asked

Viewed 41 times

0

#imagem seria um numero(reconhecer caractere)
novo = cv2.cvtColor(imagem, cv2.COLOR_BGR2GRAY)
tamanho = cv2.resize(novo, (56, 56))
converter = tamanho.astype('float32')
converter /= 255
onversao = converter.astype('int')
final = conversao.flatten()
classificador = LogisticRegression()
# conjunto de imagens
classificador.fit(x,y)
#passo somente uma imagem
previsao = classificador.predict([final])
#retorna o rotulo da imagem
return previsao

The above code returns the label referring to the image passed, but I need it to return the hit percentage.

1 answer

0

From the very example of sklearn.linear_model.LogisticRegression:

>>> from sklearn.datasets import load_iris
>>> from sklearn.linear_model import LogisticRegression
>>> X, y = load_iris(return_X_y=True)
>>> clf = LogisticRegression(random_state=0, solver='lbfgs',
...                          multi_class='multinomial').fit(X, y)
>>> clf.predict(X[:2, :])
array([0, 0])
>>> clf.predict_proba(X[:2, :]) 
array([[9.8...e-01, 1.8...e-02, 1.4...e-08],
       [9.7...e-01, 2.8...e-02, ...e-08]])

That is to say, .predict() returns the expected class, while .predict_proba() returns the percentage of belonging to each class. In the example, the classes predicted were 0 for both 2 entries, while the odds were:

  • [9.8...e-01, 1.8...e-02, 1.4...e-08], that is to say, 0.98 belonging to Class 0, 0.018 belonging to Class 1 and practically 0.0 of belonging to Class 2.
  • [9.7...e-01, 2.8...e-02, ...e-08], that is to say, 0.97 belonging to Class 0, 0.028 belonging to Class 1 and practically 0.0 of belonging to Class 2.

Browser other questions tagged

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