Matplotlib 3.0 Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

Here is the explanation of how the code works:

  • The pd.read_excel() statements read TPR and FPR data for five algorithms (KNN, MLP, SGD, RF, and DT).
  •  plt.plot([0, 1], [0, 1], 'k--') plots a black dashed line at a 45 degree angle. This is the base performance level (reference line), and an algorithm whose ROC curve is above this line and covers the largest area under it, compared to all other curves, is supposed to be the best-performing algorithm. 
  • Subsequent plt.plot() statements plot the ROC curve for each of the five chosen algorithms. Each plot statement is drawing a graph on the same axes. You can plot as many graphs as required, before plt.show(), which displays the graph on the screen.
  • Parameter labels and colors differentiate each of these algorithms on the graph. We will learn more about these parameters in subsequent chapters.
  • plt.xlabel(), plt.ylabel(), and plt.title() are the labels on the plot, and the legend is where these graph labels are placed on the graph.

You should see the following plot:

 

From the plot, it is clear that the SGD Classifier algorithm is performing poorly compared to all others, as the area under that chart is the lowest (or it is closest to the reference block dashed line). The MLP algorithm is the best among these five algorithms for this specific classification problem, since the area under this curve is the highest (or it is farthest from the reference block dashed line).