Código
import seaborn as sb
import numpy as np
from sklearn.mixture import GaussianMixture
Joel Burbano
20 de diciembre de 2023
En este post veremos un modelos de cluster
Como ya es costumbre primero importamos las librerias necesarias
Importemos los datos
Definimos el modelo
Ajustamos el modelo
GaussianMixture(n_components=3)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
GaussianMixture(n_components=3)
Determinamos las etiquetas
graficamente
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 |
---
title: Gaussian Mixture Models
author: Joel Burbano
date: 2023-12-20
categories: [Python, Aprendizaje No Supervisado, Clusters ]
---
En este post veremos un modelos de cluster
Como ya es costumbre primero importamos las librerias necesarias
```{python}
import seaborn as sb
import numpy as np
from sklearn.mixture import GaussianMixture
```
Importemos los datos
```{python}
iris=sb.load_dataset('iris')
X_iris=iris.drop('species',axis=1)
y_iris=iris['species']
```
Definimos el modelo
```{python}
Gauss=GaussianMixture(n_components=3,
covariance_type='full')
```
Ajustamos el modelo
```{python}
Gauss.fit(X_iris)
```
Determinamos las etiquetas
```{python}
y_gmm=Gauss.predict(X_iris)
```
graficamente
```{python}
iris.head()
```
```{python}
iris['cluster']=y_gmm
sb.lmplot(data=iris,x='sepal_length',y='petal_length',hue='species',col='cluster',fit_reg=False)
```