1

I am trying to use scikitplot.metrics.plot_calibration_curve to plot calibration curves for my models and would like to change the line-type (eg. dashed, solid, dotted) in the resulting charts.

The simplest reproducible example I could make is below.

import scikitplot as skplt
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split

# load the breast_cancer dataset and split it into train and test sets
X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)

rf = RandomForestClassifier()
lr = LogisticRegression()
rf_probas = rf.fit(X_train, y_train).predict_proba(X_test)
lr_probas = lr.fit(X_train, y_train).predict_proba(X_test)
clf_names = ['Random Forest', 'Logistic Regression']
probas_list = [rf_probas, lr_probas]
skplt.metrics.plot_calibration_curve(y_test,
                                      probas_list,
                                      clf_names)

Which gives exactly what I want:

enter image description here

But I would just like to be able to change the line-types, so that the chart can be printed in black and white.

Jeremy K.
  • 1,710
  • 14
  • 35
  • Judging by the documentation, the function can return two ndarrays - the proportion of positive class in each of the bins and the mean predicted probability in each of the bins. You can probably just use those and plot manually if you require a better plot. – NotAName Dec 17 '20 at 07:26
  • @pavel my apologies, I've tried reading the documentation at https://scikit-learn.org/stable/auto_examples/calibration/plot_calibration_curve.html#sphx-glr-auto-examples-calibration-plot-calibration-curve-py but couldn't work out how to return the two ndarrays. Any chance you could help? I am still learning. – Jeremy K. Dec 17 '20 at 07:33
  • Oh, sorry, I was looking at the function in scikit-learn that calculates calibration curve rather than directly plot it: https://scikit-learn.org/stable/modules/generated/sklearn.calibration.calibration_curve.html I think you should use this instead – NotAName Dec 17 '20 at 07:37
  • 2
    It's bullt on top of matplotlib so try to loop through the matplotlib axes to change the lines: https://stackoverflow.com/a/41709394/6366770 – David Erickson Dec 17 '20 at 07:42

0 Answers0