**1. Introduction**

While a single gaussian is limited. A mixture is a combination of simpler “component” distributions, which can approximate any distribution with an accuracy proportional to the number of components. It can be applied in classification, image segmentation and clustering.

A gaussian mixture model with components:

The goal is to learn the means , covariances and priors using expectation maximization (EM).

1. Random initialization the parameters of the component distributions

2. Repeat until converged

a. Assign the probability of each data point under the component parameters

b. Recalculate the parameters based on the estimated probabilities

Using The Multivariate Gaussian to compute the relative likelihood of each data point under each component.

we can simplify:**2.1 Clustering**

from sklearn.datasets.samples_generator import make_blobs import numpy as np import matplotlib.pyplot as plt import seaborn as sns sns.set() from sklearn.mixture import GaussianMixture X, y_true = make_blobs(n_samples=300, centers=4, cluster_std=0.60, random_state=0) gmm = GaussianMixture(n_components=4).fit(X) labels = gmm.predict(X) plt.scatter(X[:, 0], X[:, 1], c=labels, s=40, cmap='viridis'); plt.show()

**constrains the shape of the cluster such that all dimensions are equal**

*covariance_type="spherical"***which means that the size of the cluster along each dimension can be set independently**

*covariance_type="diag"***which allows each cluster to be modeled as an ellipse with arbitrary orientation (computa‐ tionally expensive)**

*covariance_type="full"*```
from sklearn.datasets.samples_generator import make_blobs
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
from sklearn.mixture import GaussianMixture
```

X, y = make_blobs(n_samples=1500, random_state=170) transformation = [[0.60834549, -0.63667341], [-0.40887718, 0.85253229]] X_aniso = np.dot(X, transformation) gmm = GaussianMixture(n_components=3, covariance_type="full").fit(X_aniso) probs = gmm.predict_proba(X_aniso) labels = gmm.predict(X_aniso) plt.scatter(X_aniso[:, 0], X_aniso[:, 1], c=labels, s=40, cmap='viridis'); plt.show()

**2.2 GMM as Density Estimation**

from sklearn.datasets import make_moons import numpy as np import matplotlib.pyplot as plt import seaborn as sns sns.set() from sklearn.mixture import GaussianMixture X, y = make_moons(n_samples=100, noise=0.1) gmm = GaussianMixture(n_components=10, covariance_type="full").fit(X) Xnew = gmm.sample(400)[0] plt.scatter(Xnew[:, 0], Xnew[:, 1]) plt.show()

## No comments:

## Post a Comment