Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn BaseMixture

From Leeroopedia


Knowledge Sources
Domains Mixture Models, Density Estimation
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool providing the abstract base class for all mixture models in scikit-learn.

Description

BaseMixture is an abstract base class that defines the common interface and implements shared methods for all mixture model classes, including GaussianMixture and BayesianGaussianMixture. It implements the Expectation-Maximization (EM) algorithm with support for multiple initializations, warm starts, convergence monitoring, and verbose output. Subclasses must implement abstract methods for the E-step, M-step, parameter initialization, and log-likelihood computation. The class inherits from DensityMixin and BaseEstimator.

Usage

BaseMixture is not used directly. Instead, use its concrete subclasses GaussianMixture or BayesianGaussianMixture. It provides the foundation for implementing custom mixture models by subclassing and implementing the required abstract methods.

Code Reference

Source Location

Signature

class BaseMixture(DensityMixin, BaseEstimator, metaclass=ABCMeta):
    def __init__(
        self,
        n_components,
        tol,
        reg_covar,
        max_iter,
        n_init,
        init_params,
        random_state,
        warm_start,
        verbose,
        verbose_interval,
    ):

Import

from sklearn.mixture._base import BaseMixture

I/O Contract

Inputs

Name Type Required Description
n_components int Yes Number of mixture components.
tol float Yes Convergence threshold for EM iterations.
reg_covar float Yes Regularization added to diagonal of covariance matrices.
max_iter int Yes Maximum number of EM iterations.
n_init int Yes Number of initializations; best result is kept.
init_params str Yes Initialization method for weights, means, and covariances: "kmeans", "random", "random_from_data", or "k-means++".
random_state int or RandomState Yes Random state for reproducibility.
warm_start bool Yes Whether to use solution of last fit as initialization for next fit.
verbose int Yes Verbosity level.
verbose_interval int Yes Interval between verbose log messages.

Outputs

Name Type Description
converged_ bool Whether the EM algorithm converged.
n_iter_ int Number of EM iterations performed for the best initialization.
lower_bound_ float Lower bound value on the log-likelihood of the best fit.

Usage Examples

Basic Usage

# BaseMixture is abstract; use GaussianMixture instead:
from sklearn.mixture import GaussianMixture
import numpy as np

X = np.array([[1, 2], [1, 4], [1, 0],
              [10, 2], [10, 4], [10, 0]])

gmm = GaussianMixture(n_components=2, random_state=0).fit(X)
print(gmm.predict(X))
print(gmm.converged_)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment