Documentation
Classes
GaussianMixture

GaussianMixture

Gaussian Mixture.

Representation of a Gaussian mixture model probability distribution. This class allows to estimate the parameters of a Gaussian mixture distribution.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new GaussianMixture(opts?: object): GaussianMixture;

Parameters

NameTypeDescription
opts?object-
opts.covariance_type?"full" | "tied" | "diag" | "spherical"String describing the type of covariance parameters to use. Must be one of: Default Value 'full'
opts.init_params?"k-means++" | "random" | "kmeans" | "random_from_data"The method used to initialize the weights, the means and the precisions. String must be one of: Default Value 'kmeans'
opts.max_iter?numberThe number of EM iterations to perform. Default Value 100
opts.means_init?ArrayLike[]The user-provided initial means, If it is undefined, means are initialized using the init\_params method.
opts.n_components?numberThe number of mixture components. Default Value 1
opts.n_init?numberThe number of initializations to perform. The best results are kept. Default Value 1
opts.precisions_init?ArrayLikeThe user-provided initial precisions (inverse of the covariance matrices). If it is undefined, precisions are initialized using the ‘init_params’ method. The shape depends on ‘covariance_type’:
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. Default Value 0.000001
opts.tol?numberThe convergence threshold. EM iterations will stop when the lower bound average gain is below this threshold. Default Value 0.001
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. Default Value 0
opts.verbose_interval?numberNumber of iteration done before the next print. Default Value 10
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. In that case, ‘n_init’ is ignored and only a single initialization occurs upon the first call. See the Glossary. Default Value false
opts.weights_init?ArrayLikeThe user-provided initial weights. If it is undefined, weights are initialized using the init\_params method.

Returns

GaussianMixture

Defined in: generated/mixture/GaussianMixture.ts:25 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/mixture/GaussianMixture.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/mixture/GaussianMixture.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/mixture/GaussianMixture.ts:21 (opens in a new tab)

id

string

Defined in: generated/mixture/GaussianMixture.ts:18 (opens in a new tab)

opts

any

Defined in: generated/mixture/GaussianMixture.ts:19 (opens in a new tab)

Accessors

converged_

True when convergence was reached in fit(), false otherwise.

Signature

converged_(): Promise<boolean>;

Returns

Promise<boolean>

Defined in: generated/mixture/GaussianMixture.ts:657 (opens in a new tab)

covariances_

The covariance of each mixture component. The shape depends on covariance\_type:

Signature

covariances_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/mixture/GaussianMixture.ts:582 (opens in a new tab)

feature_names_in_

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

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/mixture/GaussianMixture.ts:757 (opens in a new tab)

lower_bound_

Lower bound value on the log-likelihood (of the training data with respect to the model) of the best fit of EM.

Signature

lower_bound_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/mixture/GaussianMixture.ts:707 (opens in a new tab)

means_

The mean of each mixture component.

Signature

means_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/mixture/GaussianMixture.ts:557 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/mixture/GaussianMixture.ts:732 (opens in a new tab)

n_iter_

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

Signature

n_iter_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/mixture/GaussianMixture.ts:682 (opens in a new tab)

precisions_

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:

Signature

precisions_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/mixture/GaussianMixture.ts:607 (opens in a new tab)

precisions_cholesky_

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:

Signature

precisions_cholesky_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/mixture/GaussianMixture.ts:632 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/mixture/GaussianMixture.ts:120 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/mixture/GaussianMixture.ts:124 (opens in a new tab)

weights_

The weights of each mixture components.

Signature

weights_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/mixture/GaussianMixture.ts:532 (opens in a new tab)

Methods

aic()

Akaike information criterion for the current model on the input X.

You can refer to this mathematical section for more details regarding the formulation of the AIC used.

Signature

aic(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?any[]The input samples.

Returns

Promise<number>

Defined in: generated/mixture/GaussianMixture.ts:212 (opens in a new tab)

bic()

Bayesian information criterion for the current model on the input X.

You can refer to this mathematical section for more details regarding the formulation of the BIC used.

Signature

bic(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?any[]The input samples.

Returns

Promise<number>

Defined in: generated/mixture/GaussianMixture.ts:247 (opens in a new tab)

dispose()

Disposes of the underlying Python resources.

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

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/mixture/GaussianMixture.ts:193 (opens in a new tab)

fit()

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.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
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/GaussianMixture.ts:282 (opens in a new tab)

fit_predict()

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.

Signature

fit_predict(opts: object): Promise<any>;

Parameters

NameTypeDescription
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/GaussianMixture.ts:322 (opens in a new tab)

init()

Initializes the underlying Python resources.

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

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/mixture/GaussianMixture.ts:133 (opens in a new tab)

predict()

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

Signature

predict(opts: object): Promise<any>;

Parameters

NameTypeDescription
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/GaussianMixture.ts:360 (opens in a new tab)

predict_proba()

Evaluate the components’ density for each sample.

Signature

predict_proba(opts: object): Promise<any>;

Parameters

NameTypeDescription
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/GaussianMixture.ts:393 (opens in a new tab)

sample()

Generate random samples from the fitted Gaussian distribution.

Signature

sample(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.n_samples?numberNumber of samples to generate. Default Value 1

Returns

Promise<any>

Defined in: generated/mixture/GaussianMixture.ts:426 (opens in a new tab)

score()

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

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
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/GaussianMixture.ts:461 (opens in a new tab)

score_samples()

Compute the log-likelihood of each sample.

Signature

score_samples(opts: object): Promise<any>;

Parameters

NameTypeDescription
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/GaussianMixture.ts:499 (opens in a new tab)