Classification Evaluation metric
Classification Evaluation metric Data Science Project
Introduction to Supervised Learning with scikit-learn

Classification Evaluation metric

In this lab, we will cover **Evaluation metrics** for Classification. There are many ways to measure classification performance: Accuracy, and confusion matrices, are some of the most popular metrics. Precision & recall are widely used metrics for classification problems.
Start this project
Classification Evaluation metricClassification Evaluation metric
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.

Classification Evaluation metricClassification Evaluation metric
Project Created by

Verónica Barraza

This project is part of

Introduction to Supervised Learning with scikit-learn

Explore other projects