Python
Aprendizaje No Supervisado
Clusters
Autor/a

Joel Burbano

Fecha de publicación

20 de diciembre de 2023

En este post veremos un modelos de cluster

Como ya es costumbre primero importamos las librerias necesarias

Código
import seaborn as sb 
import numpy as np
from sklearn.mixture import GaussianMixture

Importemos los datos

Código
iris=sb.load_dataset('iris')
X_iris=iris.drop('species',axis=1)
y_iris=iris['species']

Definimos el modelo

Código
Gauss=GaussianMixture(n_components=3,
covariance_type='full')

Ajustamos el modelo

Código
Gauss.fit(X_iris)
GaussianMixture(n_components=3)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.

Determinamos las etiquetas

Código
y_gmm=Gauss.predict(X_iris)

graficamente

Código
iris.head()
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
Código
iris['cluster']=y_gmm
sb.lmplot(data=iris,x='sepal_length',y='petal_length',hue='species',col='cluster',fit_reg=False)