The score method is equivalent to calling the predict method and then the scoring.
For instance, we could have
from sklearn.metrics import accuracy_score
logistic_regression.fit(data_train, target_train)
target_predicted = logistic_regression.predict(data_test) # note that we don't pass target_test
accuracy_score(target_test, target_predicted)
If we are relying on default scores (accuracy score for classification and R2 score for regression) then we can use the score
metrics directly that combine both predict
and the score function. The above example will become:
logistic_regression.fit(data_train, target_train)
target_predicted = logistic_regression.score(data_test, target_test) # note that we pass target_test
In the end, this is a small tool avoiding a line of code but it is only valid for the default score.