Publié le 17 novembre 2024
Dans un problème de clustering, on veux déterminer les classes pour catégoriser les données
Lecture 5 min
Quand on veux répondre à cette question, on fait du clustering. Dans un problème de clustering, on veux déterminer les classes pour catégoriser les données.
Transforme les données sur une même échelle avec en valeur minimum 0 et en valeur maximal 1
from sklearn.preprocessing import MinMaxScaler
data_scaled = MinMaxScaller().fit_transform(dt)
Réduire le nombre de features en faisant des features qui regroupent des autres features
Exemples :
Ce code permet de réduire le nombre de colonne à 2 (d1 et d2)
from sklearn.manifold import TSNE
X_emb = TSNE(n_components=2).fit_transform(X)
X_emb = pd.DataFrame(X_emb, columns=['d1', 'd2'], index=X.index)
X_emb
| Type | Algo | K | Rapidité | Abérrations | Densité | Utilisation |
|---|---|---|---|---|---|---|
| Centroid | K-Means | Oui | ++ | - | Grappes convexes, sphériques et de taille similaire | |
| Graph | Affinity Propagation | Non | - | + | Grappes convexes | |
| Centroid | MeanShift | Non | - | + | Grappes | |
| Graph | Spectral Clustering | Oui | - | Anneaux, Demi-cercle, Grappes, Lignes | ||
| Graph | Ward | Non | + | Grappes | ||
| Connectiviy | Agglomerative Clustering | Non | - | |||
| Density | DBSCAN | Non | - | Anneaux, Demi-cercle, Lignes | ||
| Density | HDBSCAN | Non | + | Anneaux, Demi-cercle, Lignes | ||
| Density | OPTICS | Non | – | + | Anneaux, Demi-cercle, Lignes | |
| Compression | BIRCH | Non | + | Grappes | ||
| Distribution | Gaussian mixture | Oui | - | Lignes, Grappes |
Utilisation :
Avantages :
Inconvénients :
Paramètres :
from sklearn.cluster import KMeans
kmeans = KMeans(
n_clusters=2,
random_state=42,
init='k-means++',
n_init=10
).fit(array)
Utilisation :
Avantages :
Inconvénients :
Paramètres :
Utilisation :
Avantages :
Inconvénients :
Paramètres :
Utilisation :
Avantages :
Inconvénients :
Paramètres :
Utilisation :
Avantages :
Inconvénients :
Paramètres :
Utilisation :
Avantages :
Inconvénients :
Paramètres :
Utilisation :
Avantages :
Inconvénients :
Paramètres :
from sklearn.cluster import DBSCAN
clusering = DBSCAN(
eps=3,
min_samples=2
).fit(array)
Utilisation :
Avantages :
Inconvénients :
Paramètres :
Utilisation :
Avantages :
Inconvénients :
Paramètres :
from sklearn.cluster import OPTICS
Utilisation :
Avantages :
Inconvénients :
Paramètres :
Utilisation :
Avantages :
Inconvénients :
Paramètres :
from sklearn.mixture import GaussianMixture
Pour chaque lignes, la classe attribué : clustering.labels_
(DBSCAN attribue -1 pour les outsiders)