package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type t
val of_pyobject : Py.Object.t -> t
val to_pyobject : t -> Py.Object.t
val create : ?n_components:int -> ?covariance_type:Py.Object.t -> ?tol:float -> ?reg_covar:float -> ?max_iter:int -> ?n_init:int -> ?init_params:[ `Kmeans | `Random ] -> ?weights_init:Ndarray.t -> ?means_init:Ndarray.t -> ?precisions_init:Ndarray.t -> ?random_state:[ `Int of int | `RandomState of Py.Object.t | `None ] -> ?warm_start:bool -> ?verbose:int -> ?verbose_interval:int -> unit -> t

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 :ref:`User Guide <gmm>`.

.. versionadded:: 0.18

Parameters ---------- n_components : int, defaults to 1. The number of mixture components.

covariance_type : 'full' (default), 'tied', 'diag', 'spherical' 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

tol : float, defaults to 1e-3. The convergence threshold. EM iterations will stop when the lower bound average gain is below this threshold.

reg_covar : float, defaults to 1e-6. Non-negative regularization added to the diagonal of covariance. Allows to assure that the covariance matrices are all positive.

max_iter : int, defaults to 100. The number of EM iterations to perform.

n_init : int, defaults to 1. The number of initializations to perform. The best results are kept.

init_params : 'kmeans', 'random', defaults to 'kmeans'. The method used to initialize the weights, the means and the precisions. Must be one of::

'kmeans' : responsibilities are initialized using kmeans. 'random' : responsibilities are initialized randomly.

weights_init : array-like, shape (n_components, ), optional The user-provided initial weights, defaults to None. If it None, weights are initialized using the `init_params` method.

means_init : array-like, shape (n_components, n_features), optional The user-provided initial means, defaults to None, If it None, means are initialized using the `init_params` method.

precisions_init : array-like, optional. The user-provided initial precisions (inverse of the covariance matrices), defaults to None. If it None, precisions are initialized using the 'init_params' method. 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'

random_state : int, RandomState instance or None, optional (default=None) If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by `np.random`.

warm_start : bool, default to False. 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. In that case, 'n_init' is ignored and only a single initialization occurs upon the first call. See :term:`the Glossary <warm_start>`.

verbose : int, default to 0. 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.

verbose_interval : int, default to 10. Number of iteration done before the next print.

Attributes ---------- weights_ : array-like, shape (n_components,) The weights of each mixture components.

means_ : array-like, shape (n_components, n_features) The mean of each mixture component.

covariances_ : array-like 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'

precisions_ : array-like 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'

precisions_cholesky_ : array-like 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'

converged_ : bool True when convergence was reached in fit(), False otherwise.

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

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

See Also -------- BayesianGaussianMixture : Gaussian mixture model fit with a variational inference.

val aic : x:Ndarray.t -> t -> float

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

Parameters ---------- X : array of shape (n_samples, n_dimensions)

Returns ------- aic : float The lower the better.

val bic : x:Ndarray.t -> t -> float

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

Parameters ---------- X : array of shape (n_samples, n_dimensions)

Returns ------- bic : float The lower the better.

val fit : ?y:Py.Object.t -> x:Ndarray.t -> t -> t

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 ---------- X : array-like, shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point.

Returns ------- self

val fit_predict : ?y:Py.Object.t -> x:Ndarray.t -> t -> Ndarray.t

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 :class:`~sklearn.exceptions.ConvergenceWarning` is raised. After fitting, it predicts the most probable label for the input data points.

.. versionadded:: 0.20

Parameters ---------- X : array-like, shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point.

Returns ------- labels : array, shape (n_samples,) Component labels.

val get_params : ?deep:bool -> t -> Py.Object.t

Get parameters for this estimator.

Parameters ---------- deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns ------- params : mapping of string to any Parameter names mapped to their values.

val predict : x:Ndarray.t -> t -> Ndarray.t

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

Parameters ---------- X : array-like, shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point.

Returns ------- labels : array, shape (n_samples,) Component labels.

val predict_proba : x:Ndarray.t -> t -> Ndarray.t

Predict posterior probability of each component given the data.

Parameters ---------- X : array-like, shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point.

Returns ------- resp : array, shape (n_samples, n_components) Returns the probability each Gaussian (state) in the model given each sample.

val sample : ?n_samples:int -> t -> Ndarray.t * Ndarray.t

Generate random samples from the fitted Gaussian distribution.

Parameters ---------- n_samples : int, optional Number of samples to generate. Defaults to 1.

Returns ------- X : array, shape (n_samples, n_features) Randomly generated sample

y : array, shape (nsamples,) Component labels

val score : ?y:Py.Object.t -> x:Ndarray.t -> t -> float

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

Parameters ---------- X : array-like, shape (n_samples, n_dimensions) List of n_features-dimensional data points. Each row corresponds to a single data point.

Returns ------- log_likelihood : float Log likelihood of the Gaussian mixture given X.

val score_samples : x:Ndarray.t -> t -> Ndarray.t

Compute the weighted log probabilities for each sample.

Parameters ---------- X : array-like, shape (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point.

Returns ------- log_prob : array, shape (n_samples,) Log probabilities of each data point in X.

val set_params : ?params:(string * Py.Object.t) list -> t -> t

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form ``<component>__<parameter>`` so that it's possible to update each component of a nested object.

Parameters ---------- **params : dict Estimator parameters.

Returns ------- self : object Estimator instance.

val weights_ : t -> Ndarray.t

Attribute weights_: see constructor for documentation

val means_ : t -> Ndarray.t

Attribute means_: see constructor for documentation

val covariances_ : t -> Ndarray.t

Attribute covariances_: see constructor for documentation

val precisions_ : t -> Ndarray.t

Attribute precisions_: see constructor for documentation

val precisions_cholesky_ : t -> Ndarray.t

Attribute precisions_cholesky_: see constructor for documentation

val converged_ : t -> bool

Attribute converged_: see constructor for documentation

val n_iter_ : t -> int

Attribute n_iter_: see constructor for documentation

val lower_bound_ : t -> float

Attribute lower_bound_: see constructor for documentation

val to_string : t -> string

Print the object to a human-readable representation.

val show : t -> string

Print the object to a human-readable representation.

val pp : Format.formatter -> t -> unit

Pretty-print the object to a formatter.

OCaml

Innovation. Community. Security.