>>> from sklearn.metrics import accuracy_score >>> y_pred = [0, 2, 1, 3] >>> y_true = [0, 1, 2, 3] >>> accuracy_score(y_true, y_pred) 0.5 >>> accuracy_score(y_true, y_pred, normalize=False) 2
Here is what the above code is Doing:
1. Importing the accuracy_score function from the sklearn.metrics module.
2. Creating a list of predictions, y_pred, and a list of actual values, y_true.
3. Calculating the accuracy score using the accuracy_score function.
4. Calculating the accuracy score by setting the normalize parameter to False.
The accuracy score is the number of correct predictions divided by the total number of predictions.
The accuracy score is a good way to get a quick sense of how well a machine learning model is performing.
The accuracy score can be misleading, though, if there is a class imbalance in the data.
For example, if there are 99% of data points that are labeled as class 0 and 1% of data points that are labeled as class 1, then a model that always predicts class 0 will have an accuracy score of 99%.
This is why it’s important to look at other metrics, like precision and recall, when evaluating a machine learning model.