The sklearn.metrics.accuracy_score(y_true, y_pred)
method defines y_pred as
:
y_pred : 1d array-like, or label indicator array / sparse matrix. Predicted labels, as returned by a classifier.
Which means y_pred
has to be an array of 1's or 0's (predicated labels). They should not be probabilities.
The predicated labels (1's and 0's) and/or predicted probabilites can be generated using the LinearRegression()
model's methods predict()
and predict_proba()
respectively.
1. Generate predicted labels:
LR = linear_model.LinearRegression()
y_preds=LR.predict(X_test)
print(y_preds)
output:
[1 1 0 1]
y_preds
can now be used for the accuracy_score()
method: accuracy_score(y_true, y_pred)
2. Generate probabilities for labels:
Some metrics such as 'precision_recall_curve(y_true, probas_pred)' require probabilities, which can be generated as follows:
LR = linear_model.LinearRegression()
y_preds=LR.predict_proba(X_test)
print(y_preds)
output:
[0.87812372 0.77490434 0.30319547 0.84999743]