Je cherche à créer quelque chose comme ci-dessous en utilisant plotly, je viens juste de commencer à jouer avec la bibliothèque. Je suis capable de créer des figures en utilisant le code ci-dessous, mais je ne peux pas les rassembler sous une seule figure comme dans l'image.
from sklearn.datasets import load_iris
from sklearn import tree
import pandas as pd
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pdb
#n_classes = 3
#plot_colors = "ryb"
plot_step = 0.02
#pair = [0, 1]
iris = load_iris()
for index, pair in enumerate([[0, 1], [0, 2], [0, 3],[1, 2], [1, 3], [2, 3]]):
fig = make_subplots(rows=2,cols = 3)
i = (index//3)+1 #indexing for rows
k =(index//2)+1 #indexing for cols
#pdb.set_trace()
X = iris.data[:, pair]
y = iris.target
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X, y)
x_min, x_max = X[:, 0].min(), X[:, 0].max()
y_min, y_max = X[:, 1].min(), X[:, 1].max()
xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step),
np.arange(y_min, y_max, plot_step))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
#pdb.set_trace()
fig.add_trace(go.Contour(z = Z,
x = np.linspace(x_min,x_max,num = Z.shape[1]),
y = np.linspace(y_min,y_max,num = Z.shape[0])
),i,k)
fig.update_layout(
autosize=False,
width=1000,
height=800)
for cl in np.unique(y):
idx = np.where(y == cl)
fig.add_trace(go.Scatter(x=X[idx, 0].ravel(), y=X[idx, 1].ravel(),
mode = 'markers'),i,k)
fig.show()