Score and predict

probably i’m overwhelmed with all this knowledge but why we use score() comparing data test and target test .
“logistic_regression.score(data_test, target_test)”

The score method is used to evaluate the performance of out model with the prediction made on the data test and then use the score method comparing the target test data and the preditcion of our model .
can you please me explain this ?

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.