Regroupement par Déplacement de la Moyenne
from sklearn.cluster import MeanShift import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import make_blobs, make_moons # Create dataset for clustering X, y = make_blobs(n_samples=500, cluster_std=1, centers=4 ) transformation = [[0.6, -0.6], [-0.4, 0.8]] X_aniso = np.matmul(X, transformation) # Train Mean Shift model on blobs dataset and visualize the results blobs_clustering = MeanShift(bandwidth=2).fit(X_aniso) fig, axes = plt.subplots(1, 2) axes[0].scatter(X[:, 0], X[:, 1], c=blobs_clustering.labels_, s=50, cmap='tab20b') axes[0].set_title('Clustered anizo blobs data') axes[1].scatter(X[:, 0], X[:, 1], c=y, s=50, cmap='tab20b') axes[1].set_title('Real anizo blobs data')
from sklearn.datasets import make_moons import matplotlib.pyplot as plt from sklearn.cluster import MeanShift # Create moons dataset for clustering X, y = make_moons(n_samples=500) # Fit Mean Shift model on moons dataset and visualize the results moons_clustering = MeanShift(bandwidth=0.7).fit(X) fig,axes = plt.subplots(1,2) axes[0].scatter(X[:, 0], X[:, 1], c=moons_clustering.labels_, s=50, cmap='tab20b') axes[0].set_title('Clustered moons data') axes[1].scatter(X[:, 0], X[:, 1], c=y, s=50, cmap='tab20b') axes[1].set_title('Real moons data')
Tout était clair ?
Merci pour vos commentaires !
Section 2. Chapitre 5