Evaluation metrics for classification
Evaluation metrics for classification Data Science Project
Classification in Depth with Scikit-Learn

Evaluation metrics for classification

In this project, you'll learn the evaluation metrics used in classification problems. These metrics are interrelated, and each has its strengths and weaknesses in measuring the model's accuracy. Overall, understanding these metrics is crucial in developing effective machine learning models and making informed decisions based on their predictions.
Start this project
Evaluation metrics for classificationEvaluation metrics for classification
Project Created by

Verónica Barraza

Project Activities

All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.

All our activities include solutions with explanations on how they work and why we chose them.

input

Accuracy

A spam recognition classifier is described by the following confusion matrix:

TP, TN, FP, FN = 4, 91, 1, 4

Compute the accuracy and insert the answer in the box below.

Round to two significant decimals

input

Accuracy

A spam recogition classifier is described by the following confusion matrix:

TP, TN, FP, FN = 0, 95, 5, 0

Compute the accuracy and insert the answer in the box below.

Round to two significant decimals

input

Precision

Compute the precision based on the following results:

TP = 114 FP = 14

Round to two significant decimals

input

Recall

Compute the recall based on the following results:

TP = 114 FN = 0

Round to two significant decimals

input

F1-SCORE

Compute the F1- score based on the following results:

TP, FP, FN = 2.00, 1.00, 90.00

Round to two significant decimals

codevalidated

Evaluation Metrics for Classification

Let's now evaluate another example of how you could calculate some evaluation metrics.

# True labels of the data
y_true = [0, 1, 0, 1, 1, 0, 1, 1, 0, 0]

# Predicted labels of the data
y_pred = [0, 1, 0, 1, 0, 1, 1, 0, 1, 0]

Store the result in the variables f1,accuracy,precision and recall.

input

Fit a logistic regression model using the given input and output patterns X and Y, respectively. Once fitted, determine the precision of this fitted logistic regression model using the test dataset.

X_train = [[4,2,1],[3,4,6],[5,6,7],[8,9,7]]
y_train = [1,2,1,2]
X_test = [[4,3,1],[2,4,3],[5,6,1],[5,9,9]]
y_test = [1,2,2,2]

Use random_state=0 in the model and average='weighted'to calculate the precision. round to two decimal places the result.

input

Fit a Decision Tree model using the input patterns X and the corresponding output patterns Y. After fitting, evaluate the recall of the fitted Decision Tree model using the test dataset.

X_train = [[4,2,1],[3,4,6],[5,6,7],[8,9,7]]
y_train = [1,2,1,2]
X_test = [[4,3,1],[2,4,3],[5,6,1],[5,9,9]]
y_test = [1,2,2,2]

Use random_state=0 in the model and average='weighted'to calculate the recall. round to two decimal places the result.

multiplechoice

Fit a Decision Tree and a Logistic Regression model using the input patterns X and the corresponding output patterns Y. After fitting, compare the performance of both models in terms of F1-score and determine which one presents the best results.

from sklearn.datasets import make_blobs

X_train, y_train = make_blobs(n_samples=100, centers=2,
                  random_state=0, cluster_std=2.3)

X_test, y_test = make_blobs(n_samples=10, centers=2,
                  random_state=0, cluster_std=4.5)

Use random_state=0 in the model and average='weighted'to calculate the F1-score. round to two decimal places the result.

multiplechoice

Precision and Recall

Let’s say we have a machine that classifies if a fruit is an apple or not.

Evaluation metrics for classificationEvaluation metrics for classification
Project Created by

Verónica Barraza

This project is part of

Classification in Depth with Scikit-Learn

Explore other projects