Method for (RefLink[LearnDistribution, paclet:ref/LearnDistribution]).

Models probability density with a mixture of Gaussian (normal) distributions.

"GaussianMixture" models the probability density of a numeric space using a mixture of multivariate normal distribution.

Each Gaussian is defined by its mean and covariance matrix, as defined in the (StringTypeLink["Multinormal", paclet:ref/method/Multinormal]) method.

The following options can be given:

Possible settings for "CovarianceType" include:

Except when "CovarianceType"->"FullShared", the covariance matrices can differ from each other.

(RefLink[Information, paclet:ref/Information])[(RefLink[LearnedDistribution, paclet:ref/LearnedDistribution])[…],"MethodOption"] can be used to extract the values of options chosen by the automation system.

(RefLink[LearnDistribution, paclet:ref/LearnDistribution])[…,(RefLink[FeatureExtractor, paclet:ref/FeatureExtractor])->"Minimal"] can be used to remove most preprocessing and directly access the method.

OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Train a Gaussian mixture distribution on a numeric dataset:

ld=LearnDistribution[{1.2,2.1,3.5,4.3},Method->"GaussianMixture"]

Look at the distribution (RefLink[Information, paclet:ref/Information]):

Information[ld]

Obtain options information:

Information[ld,"MethodOption"]

Obtain an option value directly:

Information[ld,"CovarianceType"]

Compute the probability density for a new example:

PDF[ld,1.3]

Plot the PDF along with the training data:

Show[Plot[PDF[ld,x],{x,-2,8},Filling->Bottom],NumberLinePlot[{1.2,2.1,3.5,4.3},Spacings->0, PlotStyle->Red]]

Generate and visualize new samples:

Histogram[RandomVariate[ld,10000],50]

Train a Gaussian mixture distribution on a two-dimensional dataset:

iris=ExampleData[{"MachineLearning","FisherIris"},"Data"][[All,1,{1,3}]];

ld=LearnDistribution[iris,Method->"GaussianMixture"]

Plot the PDF along with the training data:

Show[ContourPlot[PDF[ld,{x,y}],{x,4,8},{y,1,7},PlotRange->All,Contours->10],ListPlot[iris, PlotStyle->Red]]

Use (RefLink[SynthesizeMissingValues, paclet:ref/SynthesizeMissingValues]) to impute missing values using the learned distribution:

SynthesizeMissingValues[ld,{5.5,Missing[]}]

Histogram[Table[Last@SynthesizeMissingValues[ld,{5.5,Missing[]}],1000]]

Train a Gaussian mixture distribution on a nominal dataset:

ld=LearnDistribution[{"A","A","B","B","B"},Method->"GaussianMixture"]

Because of the necessary preprocessing, the PDF computation is not exact:

PDF[ld,"A"]

PDF[ld,"A"]

Use (RefLink[ComputeUncertainty, paclet:ref/ComputeUncertainty]) to obtain the uncertainty on the result:

PDF[ld,"A",ComputeUncertainty->True]

Increase (RefLink[MaxIterations, paclet:ref/MaxIterations]) to improve the estimation precision:

PDF[ld,"A",MaxIterations->1000,ComputeUncertainty->True]

OpenersExampleSection1(Spacer1)Options  (3)

OpenersExampleSubsection0(Spacer1)"ComponentsNumber"  (1)

Train a "GaussianMixture" distribution with 3 components:

iris=ExampleData[{"MachineLearning","FisherIris"},"Data"][[All,1,{1,3}]];

ld=LearnDistribution[iris,Method->{"GaussianMixture","ComponentsNumber"->3}]

Evaluate the PDF of the distribution at a specific point:

PDF[ld,{6,4}]

Visualize the PDF obtained after training a mixture of Gaussians with 1, 2, 3, and 10 components:

plots=(ld=LearnDistribution[iris,Method->{"GaussianMixture","ComponentsNumber"->#},FeatureExtractor->"Minimal"];
Show[ContourPlot[PDF[ld,{x,y}],{x,2,10},{y,0,8},PlotRange->All,Contours->10,PlotLabel->ToString[#] <>" "<>Pluralize["component",#]],ListPlot[iris, PlotStyle->Red],ImageSize->250]) & /@ {1,2,3,10};

Grid[Partition[plots,2]]

OpenersExampleSubsection1(Spacer1)"CovarianceType"  (1)

Train a "GaussianMixture" distribution with a "Full" covariance:

iris=ExampleData[{"MachineLearning","FisherIris"},"Data"][[All,1,{1,3}]];

ld=LearnDistribution[iris,Method->{"GaussianMixture","CovarianceType"->"Full"}]

Evaluate the PDF of the distribution at a specific point:

PDF[ld,{6,4}]

Visualize the PDF obtained after training a mixture of two Gaussians with covariance types "Full", "Diagonal", "Spherical" and "FullShared":

plots=(ld=LearnDistribution[iris,Method->{"GaussianMixture","ComponentsNumber"->2, "CovarianceType"->#},FeatureExtractor->"Minimal"];
Show[ContourPlot[PDF[ld,{x,y}],{x,2,10},{y,0,8},PlotRange->All,Contours->10,PlotLabel->#<>" covariance"],ListPlot[iris, PlotStyle->Red],ImageSize->250]) & /@ {"Full","Diagonal","Spherical","FullShared"};

Grid[Partition[plots,2]]

Perform the same operation but with an automatic number of Gaussians for each covariance type:

plots=(ld=LearnDistribution[iris,Method->{"GaussianMixture", "CovarianceType"->#},FeatureExtractor->"Minimal"];
Show[ContourPlot[PDF[ld,{x,y}],{x,2,10},{y,0,8},PlotRange->All,Contours->10,PlotLabel->#<>" covariance"],ListPlot[iris, PlotStyle->Red],ImageSize->250]) & /@ {"Full","Diagonal","Spherical","FullShared"};

Grid[Partition[plots,2]]

OpenersExampleSubsection2(Spacer1)Maxiterations  (1)

Train a "GaussianMixture" distribution while limiting the number of expectation–maximization iterations to 10:

iris=ExampleData[{"MachineLearning","FisherIris"},"Data"][[All,1,{1,3}]];

ld=LearnDistribution[iris,Method->{"GaussianMixture",MaxIterations->10}]

Evaluate the PDF of the distribution at a specific point:

PDF[ld,{6,4}]

Visualize the convergence of the expectation–maximization algorithm for a two-component distribution:

plots=(
ld=LearnDistribution[iris,Method->{"GaussianMixture",MaxIterations->#,"ComponentsNumber"->2},FeatureExtractor->"Minimal"];
Show[ContourPlot[PDF[ld,{x,y}],{x,2,10},{y,0,8},PlotRange->All,Contours->10, PlotLabel->Row[{#," ",Pluralize["iteration", #]}]],ListPlot[iris, PlotStyle->Red],ImageSize->250]
) & /@ {1,2,3, 4,5,6};

Grid[Partition[plots,2]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LearnDistribution, paclet:ref/LearnDistribution])  ▪  (RefLink[LearnedDistribution, paclet:ref/LearnedDistribution])  ▪  (RefLink[MultinormalDistribution, paclet:ref/MultinormalDistribution])  ▪  (RefLink[NormalDistribution, paclet:ref/NormalDistribution])  ▪  (RefLink[MixtureDistribution, paclet:ref/MixtureDistribution])  ▪  (RefLink[AnomalyDetection, paclet:ref/AnomalyDetection])  ▪  (RefLink[SynthesizeMissingValues, paclet:ref/SynthesizeMissingValues])  ▪  (RefLink[RandomVariate, paclet:ref/RandomVariate])  ▪  (RefLink[PDF, paclet:ref/PDF])  ▪  (RefLink[RarerProbability, paclet:ref/RarerProbability])  ▪    ▪    ▪  }, {Related Machine Learning Methods:  (RefLink[Multinormal, paclet:ref/method/Multinormal])  ▪  (RefLink[KernelDensityEstimation, paclet:ref/method/KernelDensityEstimation])  ▪  (RefLink[ContingencyTable, paclet:ref/method/ContingencyTable])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/22-machine-learning.html])(WebLink[: Machine Learning, https://www.wolfram.com/language/elementary-introduction/22-machine-learning.html])}})}})