1. Importing the Required Library
from sklearn.metrics import accuracy_score
sklearn.metrics: This is a module in the Scikit-Learn library that provides functions to evaluate the performance of machine learning models.
accuracy_score(): This function calculates the accuracy of a model's predictions.
It compares the predicted values to the actual values and computes the accuracy using the formula:
Accuracy=Number of Correct Predictions/Total Number of Predictions
2. Defining the Actual Values (True Labels)
y_true = [0, 1, 1, 0]
y_true represents the actual values or ground truth labels.
In this case, there are 4 data points labeled as 0 or 1.
0: Usually represents Negative (e.g., No disease, No spam, etc.)
1: Represents Positive (e.g., Disease present, Spam detected, etc.)
3. Defining the Predicted Values
y_pred = [0, 1, 0, 0]
y_pred contains the predictions made by a machine learning model for the same 4 data points.
Each value is either 0 or 1, indicating the predicted class.
4. Calculating the Accuracy Score
print(accuracy_score(y_true, y_pred))
The accuracy_score() function takes two inputs:
y_true → Actual values
y_pred → Predicted values
0 Comments:
Post a Comment