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.
Added in version 0.18.
Read more in the User Guide.
The 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.
String describing the type of covariance parameters to use. Must be one of:
‘full’ (each component has its own general covariance matrix),
‘tied’ (all components share the same general covariance matrix),
‘diag’ (each component has its own diagonal covariance matrix),
‘spherical’ (each component has its own single variance).
The 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.
Non-negative regularization added to the diagonal of covariance. Allows to assure that the covariance matrices are all positive.
The number of EM iterations to perform.
The number of initializations to perform. The result with the highest lower bound value on the likelihood is kept.
The method used to initialize the weights, the means and the covariances. String must be one of:
‘kmeans’: responsibilities are initialized using kmeans.
‘k-means++’: use the k-means++ method to initialize.
‘random’: responsibilities are initialized randomly.
‘random_from_data’: initial means are randomly selected data points.
Changed in version v1.1: init_params
now accepts ‘random_from_data’ and ‘k-means++’ as initialization methods.
String describing the type of the weight concentration prior.
The 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 None, it’s set to 1. / n_components
.
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
. The value of the parameter must be greater than 0. If it is None, it is set to 1.
The prior on the mean distribution (Gaussian). If it is None, it is set to the mean of X.
The prior of the number of degrees of freedom on the covariance distributions (Wishart). If it is None, it’s set to n_features
.
The prior on the covariance distribution (Wishart). If it is None, the emiprical covariance prior is initialized using the covariance of X. The shape depends on covariance_type
:
(n_features, n_features) if 'full', (n_features, n_features) if 'tied', (n_features) if 'diag', float if 'spherical'
Controls 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.
If ‘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.
Enable 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.
Number of iteration done before the next print.
The weights of each mixture components.
The mean of each mixture component.
The covariance of each mixture component. The shape depends on covariance_type
:
(n_components,) if 'spherical', (n_features, n_features) if 'tied', (n_components, n_features) if 'diag', (n_components, n_features, n_features) if 'full'
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
:
(n_components,) if 'spherical', (n_features, n_features) if 'tied', (n_components, n_features) if 'diag', (n_components, n_features, n_features) if 'full'
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
:
(n_components,) if 'spherical', (n_features, n_features) if 'tied', (n_components, n_features) if 'diag', (n_components, n_features, n_features) if 'full'
True when convergence of the best fit of inference was reached, False otherwise.
Number of step used by the best fit of inference to reach the convergence.
Lower bound value on the model evidence (of the training data) of the best fit of inference.
n_iter_
,)
The list of lower bound values on the model evidence from each iteration of the best fit of inference.
The dirichlet concentration of each component on the weight distribution (Dirichlet). The type depends on weight_concentration_prior_type
:
(float, float) if 'dirichlet_process' (Beta parameters), float if 'dirichlet_distribution' (Dirichlet parameters).
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 simplex.
The dirichlet concentration of each component on the weight distribution (Dirichlet).
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 None, mean_precision_prior_
is set to 1.
The precision of each components on the mean distribution (Gaussian).
The prior on the mean distribution (Gaussian).
The prior of the number of degrees of freedom on the covariance distributions (Wishart).
The number of degrees of freedom of each components in the model.
The prior on the covariance distribution (Wishart). The shape depends on covariance_type
:
(n_features, n_features) if 'full', (n_features, n_features) if 'tied', (n_features) if 'diag', float if 'spherical'
Number of features seen during fit.
Added in version 0.24.
n_features_in_
,)
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Added in version 1.0.
References
Examples
>>> import numpy as np >>> from sklearn.mixture import BayesianGaussianMixture >>> X = np.array([[1, 2], [1, 4], [1, 0], [4, 2], [12, 4], [10, 7]]) >>> bgm = BayesianGaussianMixture(n_components=2, random_state=42).fit(X) >>> bgm.means_ array([[2.49 , 2.29], [8.45, 4.52 ]]) >>> bgm.predict([[0, 0], [9, 3]]) array([0, 1])
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.
List of n_features-dimensional data points. Each row corresponds to a single data point.
Not used, present for API consistency by convention.
The fitted mixture.
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.
Added in version 0.20.
List of n_features-dimensional data points. Each row corresponds to a single data point.
Not used, present for API consistency by convention.
Component labels.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
A MetadataRequest
encapsulating routing information.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict the labels for the data samples in X using trained model.
List of n_features-dimensional data points. Each row corresponds to a single data point.
Component labels.
Evaluate the components’ density for each sample.
List of n_features-dimensional data points. Each row corresponds to a single data point.
Density of each Gaussian component for each sample in X.
Generate random samples from the fitted Gaussian distribution.
Number of samples to generate.
Randomly generated sample.
Component labels.
Compute the per-sample average log-likelihood of the given data X.
List of n_features-dimensional data points. Each row corresponds to a single data point.
Not used, present for API consistency by convention.
Log-likelihood of X
under the Gaussian mixture model.
Compute the log-likelihood of each sample.
List of n_features-dimensional data points. Each row corresponds to a single data point.
Log-likelihood of each sample in X
under the current model.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline
). The latter have parameters of the form <component>__<parameter>
so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4