VOOZH about

URL: https://www.geeksforgeeks.org/machine-learning/difference-between-score-and-accuracy_score-methods-in-scikit-learn/

⇱ Difference between score() and accuracy_score() methods in scikit-learn - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Difference between score() and accuracy_score() methods in scikit-learn

Last Updated : 23 Jul, 2025

The score( ) method and accuracy_score( ) function are both essential tools in evaluating machine learning models, especially in supervised learning tasks. While they both assess model performance in terms of accuracy, they differ in terms of usage, flexibility, and application. Understanding these differences is crucial for effectively evaluating and comparing machine learning models.

Score Vs Accuracy Score

Aspect

'score' method

'accuracy_score' function

Usage

This method can be called on the model object, score method refers to model object. For example, in sci-kit-learn after creating a model like ' Logistic Regression( ) ' , you have an object 'model' that represents this specific trained logistic regression model.

The 'accuracy_score( ) ' function is a standalone function from the metrics module. This function does not need to be tied to a specific object or class.

Functionality

This method evaluates the model on test data.

This method compares predicted values with the true values.

Arguments

Takes test data directly

Takes predicted labels and true labels as arguments.

Flexibility

This method is less flexible as compare to accuracy_score function

This method is more flexible .

Performance comparison

Useful for quick model evaluation

Useful for comparing multiple models.

Implementation: score() method vs accuracy_score() function in python

Below is an example of implementation demonstrating the difference between two evaluation methods using a simple logistic regression model in scikit-learn -

Step 1: Importing the necessary libraries

We will import necessary modules for logistic regression, accuracy evaluation, iris dataset loading, and train-test splitting, facilitating the development and assessment of a logistic regression model for classification tasks.


Step 2 : Loading the iris dataset

Once ,we have loaded the necessary libraries, we will be loading Iris Dataset into variables "X" and "y" representing the feature matrix and target labels, respectively.


Step 3 : Splitting the dataset into training and testing sets

This code splits the dataset into training and testing sets, with 80% of the data reserved for training (X_train, y_train) and 20% for testing (X_test, y_test), ensuring consistency in random splitting with a specified seed value (random_state=42).


Step 4 : Create and Train a logistic Regression model and train on training dataset

We create a logistic regression model instance and trains it on the training data (X_train, y_train) to learn the relationships between the features and target labels.

Step 5 : Model Evaluation

score() method

Then, we evaluate the trained logistic regression model's performance on the test data (X_test, y_test) using the score() method, which computes the accuracy of the model's predictions compared to the actual target labels. It then prints out the accuracy score.

Output :

Score method - Accuracy: 1.0

accuracy_score()

The provided code generates predictions (y_pred) from the trained logistic regression model on the test data (X_test). Then, it computes the accuracy of the model's predictions compared to the actual target labels (y_test) using the accuracy_score function, which measures the proportion of correctly predicted labels. Finally, it prints out the accuracy score obtained from the accuracy_score function.

Output :

accuracy_score function - Accuracy: 1.0

In this implementation, we train a logistic regression model on the Iris dataset and then evaluate its accuracy using both the score() method and accuracy_score() function. The output will demonstrate the same accuracy value obtained using both approaches, showcasing their equivalence in evaluating model accuracy.

Comment