DocumentationClassesBayesianGaussianMixture

Class: BayesianGaussianMixture

Variational Bayesian estimation of a Gaussian mixture.

This class allows to infer an approximate posterior distribution over the parameters of a Gaussian mixture distribution. The effective number of components can be inferred from the data.

This class implements two types of prior for the weights distribution: a finite mixture model with Dirichlet distribution and an infinite mixture model with the Dirichlet Process. In practice Dirichlet Process inference algorithm is approximated and uses a truncated distribution with a fixed maximum number of components (called the Stick-breaking representation). The number of components actually used almost always depends on the data.

Python Reference

Constructors

new BayesianGaussianMixture()

new BayesianGaussianMixture(opts?): BayesianGaussianMixture

Parameters

ParameterTypeDescription
opts?object-
opts.covariance_prior?number | ArrayLikeThe prior on the covariance distribution (Wishart). If it is undefined, the emiprical covariance prior is initialized using the covariance of X. The shape depends on covariance_type:
opts.covariance_type?"full" | "tied" | "diag" | "spherical"String describing the type of covariance parameters to use. Must be one of:
opts.degrees_of_freedom_prior?numberThe prior of the number of degrees of freedom on the covariance distributions (Wishart). If it is undefined, it’s set to n_features.
opts.init_params?"k-means++" | "random" | "kmeans" | "random_from_data"The method used to initialize the weights, the means and the covariances. String must be one of:
opts.max_iter?numberThe number of EM iterations to perform.
opts.mean_precision_prior?numberThe precision prior on the mean distribution (Gaussian). Controls the extent of where means can be placed. Larger values concentrate the cluster means around mean_prior. The value of the parameter must be greater than 0. If it is undefined, it is set to 1.
opts.mean_prior?ArrayLikeThe prior on the mean distribution (Gaussian). If it is undefined, it is set to the mean of X.
opts.n_components?numberThe number of mixture components. Depending on the data and the value of the weight_concentration_prior the model can decide to not use all the components by setting some component weights_ to values very close to zero. The number of effective components is therefore smaller than n_components.
opts.n_init?numberThe number of initializations to perform. The result with the highest lower bound value on the likelihood is kept.
opts.random_state?numberControls the random seed given to the method chosen to initialize the parameters (see init_params). In addition, it controls the generation of random samples from the fitted distribution (see the method sample). Pass an int for reproducible output across multiple function calls. See Glossary.
opts.reg_covar?numberNon-negative regularization added to the diagonal of covariance. Allows to assure that the covariance matrices are all positive.
opts.tol?numberThe convergence threshold. EM iterations will stop when the lower bound average gain on the likelihood (of the training data with respect to the model) is below this threshold.
opts.verbose?numberEnable verbose output. If 1 then it prints the current initialization and each iteration step. If greater than 1 then it prints also the log probability and the time needed for each step.
opts.verbose_interval?numberNumber of iteration done before the next print.
opts.warm_start?booleanIf ‘warm_start’ is true, the solution of the last fitting is used as initialization for the next call of fit(). This can speed up convergence when fit is called several times on similar problems. See the Glossary.
opts.weight_concentration_prior?numberThe dirichlet concentration of each component on the weight distribution (Dirichlet). This is commonly called gamma in the literature. The higher concentration puts more mass in the center and will lead to more components being active, while a lower concentration parameter will lead to more mass at the edge of the mixture weights simplex. The value of the parameter must be greater than 0. If it is undefined, it’s set to 1. / n_components.
opts.weight_concentration_prior_type?"dirichlet_process" | "dirichlet_distribution"String describing the type of the weight concentration prior.

Returns BayesianGaussianMixture

Defined in generated/mixture/BayesianGaussianMixture.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/mixture/BayesianGaussianMixture.ts:23
_isInitializedbooleanfalsegenerated/mixture/BayesianGaussianMixture.ts:22
_pyPythonBridgeundefinedgenerated/mixture/BayesianGaussianMixture.ts:21
idstringundefinedgenerated/mixture/BayesianGaussianMixture.ts:18
optsanyundefinedgenerated/mixture/BayesianGaussianMixture.ts:19

Accessors

converged_

Get Signature

get converged_(): Promise<boolean>

True when convergence of the best fit of inference was reached, false otherwise.

Returns Promise<boolean>

Defined in generated/mixture/BayesianGaussianMixture.ts:654


covariance_prior_

Get Signature

get covariance_prior_(): Promise<number | ArrayLike>

The prior on the covariance distribution (Wishart). The shape depends on covariance_type:

Returns Promise<number | ArrayLike>

Defined in generated/mixture/BayesianGaussianMixture.ts:924


covariances_

Get Signature

get covariances_(): Promise<ArrayLike>

The covariance of each mixture component. The shape depends on covariance_type:

Returns Promise<ArrayLike>

Defined in generated/mixture/BayesianGaussianMixture.ts:573


degrees_of_freedom_

Get Signature

get degrees_of_freedom_(): Promise<ArrayLike>

The number of degrees of freedom of each components in the model.

Returns Promise<ArrayLike>

Defined in generated/mixture/BayesianGaussianMixture.ts:897


degrees_of_freedom_prior_

Get Signature

get degrees_of_freedom_prior_(): Promise<number>

The prior of the number of degrees of freedom on the covariance distributions (Wishart).

Returns Promise<number>

Defined in generated/mixture/BayesianGaussianMixture.ts:870


feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/mixture/BayesianGaussianMixture.ts:978


lower_bound_

Get Signature

get lower_bound_(): Promise<number>

Lower bound value on the model evidence (of the training data) of the best fit of inference.

Returns Promise<number>

Defined in generated/mixture/BayesianGaussianMixture.ts:708


mean_precision_

Get Signature

get mean_precision_(): Promise<ArrayLike>

The precision of each components on the mean distribution (Gaussian).

Returns Promise<ArrayLike>

Defined in generated/mixture/BayesianGaussianMixture.ts:816


mean_precision_prior_

Get Signature

get mean_precision_prior_(): Promise<number>

The precision prior on the mean distribution (Gaussian). Controls the extent of where means can be placed. Larger values concentrate the cluster means around mean_prior. If mean_precision_prior is set to undefined, mean_precision_prior_ is set to 1.

Returns Promise<number>

Defined in generated/mixture/BayesianGaussianMixture.ts:789


mean_prior_

Get Signature

get mean_prior_(): Promise<ArrayLike>

The prior on the mean distribution (Gaussian).

Returns Promise<ArrayLike>

Defined in generated/mixture/BayesianGaussianMixture.ts:843


means_

Get Signature

get means_(): Promise<ArrayLike[]>

The mean of each mixture component.

Returns Promise<ArrayLike[]>

Defined in generated/mixture/BayesianGaussianMixture.ts:546


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/mixture/BayesianGaussianMixture.ts:951


n_iter_

Get Signature

get n_iter_(): Promise<number>

Number of step used by the best fit of inference to reach the convergence.

Returns Promise<number>

Defined in generated/mixture/BayesianGaussianMixture.ts:681


precisions_

Get Signature

get precisions_(): Promise<ArrayLike>

The precision matrices for each component in the mixture. A precision matrix is the inverse of a covariance matrix. A covariance matrix is symmetric positive definite so the mixture of Gaussian can be equivalently parameterized by the precision matrices. Storing the precision matrices instead of the covariance matrices makes it more efficient to compute the log-likelihood of new samples at test time. The shape depends on covariance_type:

Returns Promise<ArrayLike>

Defined in generated/mixture/BayesianGaussianMixture.ts:600


precisions_cholesky_

Get Signature

get precisions_cholesky_(): Promise<ArrayLike>

The cholesky decomposition of the precision matrices of each mixture component. A precision matrix is the inverse of a covariance matrix. A covariance matrix is symmetric positive definite so the mixture of Gaussian can be equivalently parameterized by the precision matrices. Storing the precision matrices instead of the covariance matrices makes it more efficient to compute the log-likelihood of new samples at test time. The shape depends on covariance_type:

Returns Promise<ArrayLike>

Defined in generated/mixture/BayesianGaussianMixture.ts:627


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/mixture/BayesianGaussianMixture.ts:139


weight_concentration_

Get Signature

get weight_concentration_(): Promise<ArrayLike>

The dirichlet concentration of each component on the weight distribution (Dirichlet).

Returns Promise<ArrayLike>

Defined in generated/mixture/BayesianGaussianMixture.ts:762


weight_concentration_prior_

Get Signature

get weight_concentration_prior_(): Promise<number>

The dirichlet concentration of each component on the weight distribution (Dirichlet). The type depends on weight_concentration_prior_type:

Returns Promise<number>

Defined in generated/mixture/BayesianGaussianMixture.ts:735


weights_

Get Signature

get weights_(): Promise<ArrayLike>

The weights of each mixture components.

Returns Promise<ArrayLike>

Defined in generated/mixture/BayesianGaussianMixture.ts:519

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/mixture/BayesianGaussianMixture.ts:195


fit()

fit(opts): Promise<any>

Estimate model parameters with the EM algorithm.

The method fits the model n_init times and sets the parameters with which the model has the largest likelihood or lower bound. Within each trial, the method iterates between E-step and M-step for max_iter times until the change of likelihood or lower bound is less than tol, otherwise, a ConvergenceWarning is raised. If warm_start is true, then n_init is ignored and a single initialization is performed upon the first call. Upon consecutive calls, training starts where it left off.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]List of n_features-dimensional data points. Each row corresponds to a single data point.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<any>

Defined in generated/mixture/BayesianGaussianMixture.ts:214


fit_predict()

fit_predict(opts): Promise<any>

Estimate model parameters using X and predict the labels for X.

The method fits the model n_init times and sets the parameters with which the model has the largest likelihood or lower bound. Within each trial, the method iterates between E-step and M-step for max_iter times until the change of likelihood or lower bound is less than tol, otherwise, a ConvergenceWarning is raised. After fitting, it predicts the most probable label for the input data points.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]List of n_features-dimensional data points. Each row corresponds to a single data point.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<any>

Defined in generated/mixture/BayesianGaussianMixture.ts:255


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/mixture/BayesianGaussianMixture.ts:298


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/mixture/BayesianGaussianMixture.ts:152


predict()

predict(opts): Promise<any>

Predict the labels for the data samples in X using trained model.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]List of n_features-dimensional data points. Each row corresponds to a single data point.

Returns Promise<any>

Defined in generated/mixture/BayesianGaussianMixture.ts:334


predict_proba()

predict_proba(opts): Promise<any>

Evaluate the components’ density for each sample.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]List of n_features-dimensional data points. Each row corresponds to a single data point.

Returns Promise<any>

Defined in generated/mixture/BayesianGaussianMixture.ts:370


sample()

sample(opts): Promise<any>

Generate random samples from the fitted Gaussian distribution.

Parameters

ParameterTypeDescription
optsobject-
opts.n_samples?numberNumber of samples to generate.

Returns Promise<any>

Defined in generated/mixture/BayesianGaussianMixture.ts:406


score()

score(opts): Promise<number>

Compute the per-sample average log-likelihood of the given data X.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]List of n_features-dimensional data points. Each row corresponds to a single data point.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<number>

Defined in generated/mixture/BayesianGaussianMixture.ts:444


score_samples()

score_samples(opts): Promise<any>

Compute the log-likelihood of each sample.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]List of n_features-dimensional data points. Each row corresponds to a single data point.

Returns Promise<any>

Defined in generated/mixture/BayesianGaussianMixture.ts:483