- Matplotlib 3.0 Cookbook
- Srinivasa Rao Poladi
- 185字
- 2025-04-04 16:06:37
Getting ready
We will use an example of an Receiver Operating Characteristics (ROC) curve, using which multiple machine learning (ML) algorithms are compared to a given classification problem, and the best performing algorithm is chosen for that problem. An ROC curve is plotted with a True Positive Rate (TPR) and a False Positive Rate (FPR) for a range of threshold probabilities. The objective is to see the sensitivity of the TPR and the FPR as the threshold probability changes. The algorithm whose ROC curve covers the maximum area under the curve (AUC) is considered to be the best performing algorithm in terms of classification accuracy.
We are using TPR and FPR data for a set of algorithms, the k-nearest neighbor algorithm (k-NN), multilayer perceptron (MLP), Stochastic Gradient Descent (SGD), random forest (RF), and decision tree (DT), run on a classification problem to plot the graphs. This dataset is provided as part of the code library for this book.
Import the required libraries:
import matplotlib.pyplot as plt
import pandas as pd