alibi_detect.od.sklearn.gmm module

class alibi_detect.od.sklearn.gmm.GMMSklearn(n_components)[source]

Bases: SklearnOutlierDetector

__init__(n_components)[source]

sklearn backend for the Gaussian Mixture Model (GMM) outlier detector.

Parameters:

n_components (int) – Number of components in gaussian mixture model.

Raises:

ValueError – If n_components is less than 1.

fit(x_ref, tol=0.001, max_iter=100, n_init=1, init_params='kmeans', verbose=0)[source]

Fit the SKLearn GMM model`.

Parameters:
  • x_ref (ndarray) – Reference data.

  • tol (float) – Convergence threshold. EM iterations will stop when the lower bound average gain is below this threshold.

  • max_iter (int) – Maximum number of EM iterations to perform.

  • n_init (int) – Number of initializations to perform.

  • init_params (str) – Method used to initialize the weights, the means and the precisions. Must be one of: ‘kmeans’ : responsibilities are initialized using kmeans. ‘kmeans++’ : responsibilities are initialized using kmeans++. ‘random’ : responsibilities are initialized randomly. ‘random_from_data’ : responsibilities are initialized randomly from the data.

  • verbose (int) – 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.

Return type:

Dict

Returns:

Dictionary with fit results. The dictionary contains the following keys

  • converged: bool indicating whether EM algorithm converged.

  • n_iter: number of EM iterations performed.

  • lower_bound: log-likelihood lower bound.

format_fit_kwargs(fit_kwargs)[source]

Format kwargs for fit method.

Parameters:

kwargs – dictionary of Kwargs to format. See fit method for details.

Return type:

Dict

Returns:

Formatted kwargs.

score(x)[source]

Computes the score of x

Parameters:

x (ndarray) – np.ndarray with leading batch dimension.

Return type:

ndarray

Returns:

np.ndarray of scores with leading batch dimension.

Raises:

NotFittedError – Raised if method called and detector has not been fit.