How to plot a Probability Calibration Curve using plotly-python?

Sample Data:

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split

X, y = make_classification(
    n_samples=100_000, n_features=20, n_informative=2, n_redundant=10, random_state=42
)

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.99, random_state=42
)

I wanted to plot a Calibration Curve plot using plotly,Using the below matplotlib code as reference

from sklearn.calibration import CalibratedClassifierCV, CalibrationDisplay
from sklearn.tree import DecisionTreeClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier, ExtraTreesClassifier
from sklearn.ensemble import GradientBoostingClassifier, ExtraTreesClassifier

rs = {'random_state': 42}

# ------------------------------------------------------ initiate Classifiers
lgr = LogisticRegression(**rs, max_iter=3000, verbose=True, n_jobs=-1)
mlp = MLPClassifier(max_iter=1000, **rs)
dt = DecisionTreeClassifier(**rs)
et = ExtraTreesClassifier(**rs, verbose=True, n_jobs=-1)
rf = RandomForestClassifier(**rs, verbose=True, n_jobs=-1)
xgb = XGBClassifier(**rs, verbosity=0)
abc = AdaBoostClassifier(n_estimators=100, **rs)
gbm = GradientBoostingClassifier(**rs)
# use_best_model params will make the model prevent overfitting
cat = CatBoostClassifier(iterations=1000, 
                            learning_rate=0.01, 
                            depth=5, 
                            loss_function= 'Logloss', 
                            eval_metric='Accuracy', # 'Precision', 'Recall', 'F1'
                        #  use_best_model=True,
                            silent=True,
                            random_seed=SEED)

clf_list  = [('LogisticRegression', lgr), 
                ('MLP', mlp),
                ('DecisionTree', dt),
                ('ExtraTrees', et),
                ('RandomForest', rf),
                ('XGBoost', xgb),
                ('AdaBoostClassifier', abc),
                ('GBClassifier', gbm),
                ('CatBoost', cat)]

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

fig = plt.figure(figsize=(10, 15))
gs = GridSpec(5, 3)
colors = plt.cm.get_cmap("Dark2")

ax_calibration_curve = fig.add_subplot(gs[:2, :3])
calibration_displays = {}
for i, (name, clf) in enumerate(clf_list):
    clf.fit(X_train, y_train)
    display = CalibrationDisplay.from_estimator(
        clf,
        X_test,
        y_test,
        n_bins=10,
        name=name,
        ax=ax_calibration_curve,
        color=colors(i),
    )
    calibration_displays[name] = display

ax_calibration_curve.grid()
ax_calibration_curve.set_title("Calibration plots")

# Add histogram
# grid_positions = [(2, 0), (2, 1), (3, 0), (3, 1)]

grid_positions = [(2, 0), (2, 1),(2, 2),(3,0),(3,1),(3,2),(4,0),(4,1),(4,2) ]
for i, (name, _) in enumerate(clf_list):
    row, col = grid_positions[i]
    ax = fig.add_subplot(gs[row, col])

    ax.hist(
        calibration_displays[name].y_prob,
        range=(0, 1),
        bins=10,
        label=name,
        color=colors(i),
    )
    ax.set(title=name, xlabel="Mean predicted probability", ylabel="Count")

plt.tight_layout()
plt.show()

enter image description here

Here the CalibrationDisplay from scikit-learn is an object which is added to matplotlib subplot.

<sklearn.calibration.CalibrationDisplay object at 0x7f7ee5098850>

Is it possible to add the CalibrationDisplay to plotly? How to plot this calibration curve in plotly?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum