Unit 5 of 8 · about 3 hours · derive

Gaussian mixtures and EM

Mixtures turn distance into probability: overlapping groups get graded membership plus density scores that the anomaly unit spends.

You'll be able to

  • Explain responsibilities as posterior component membership and the EM loop as alternating and steps.
  • Derive the 1D M-step updates for means, variances and weights from weighted maximum likelihood.
  • Select the component count with BIC or AIC and state why a plain GaussianMixture always uses every component.

Covers

Gaussian mixtures, responsibilities and EM intuition
1

Read

In this order, only the parts listed

0 of 2 done

  1. Mixture fits, covariances and component countHands-On Machine Learning with Scikit-Learn and PyTorch - dimensionality reduction and unsupervised learning

    Book Chapter 8: Gaussian Mixtures through Selecting the Number of Clusters (printed pp. 269-278). Notebook 08 cells: Gaussian Mixtures: EM-fitted weights, means and covariances on the three-ellipsoid data with the covariance_type full, tied, spherical and diag comparison; Selecting the Number of Clusters with the BIC and AIC formulas and the minimum at

    Skim Bayesian Gaussian Mixture Models; variational inference is later work. Keep the BIC and AIC minimum plot.

  2. EM estimation, init and failure modesscikit-learn - decomposition, clustering and outlier detection

    2.1.1 Gaussian Mixture: EM E-step and M-step description, covariance options, the singularity and always-uses-all-components cons, and the BIC asymptotic note; Choice of the Initialization method with the k-means default

2

Focus on

  • Responsibilities are posteriors that sum to one per point. The M-step refits each Gaussian to responsibility-weighted data.
  • Likelihood rises every EM round but only to a local optimum. Starts matter; the sklearn default starts from k-means.
  • Full covariance needs parameters per component. Few points per component invite singular covariances; reg_covar (1e-6 by default) adds to the diagonal to keep them invertible.
  • BIC penalizes parameters with . It recovers the true count only asymptotically under a true mixture; on real data it is a guide, not proof.
Common mistakes · 3
  • Dividing the M-step variance by . Mixture MLE divides by the responsibility sum, which is for , giving 2.6667 on , not 4.0.
  • Reading converged likelihood as a global optimum. Different starts converge differently; report spread, not one run.
  • Trusting the BIC minimum as truth on misspecified data. The docs note asymptotic recovery needs data truly drawn from a mixture.
3

Try it yourself

Closed-book, before checking anything

Closed-book, write the 1D E-step responsibility formula and the M-step updates for mean, variance with MLE denominator, and weight. Run the case on : mean 4.0 and variance 8/3=2.6667.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.What does responsibility 0.9 of point under component 2 mean?Answer

    Posterior membership: under current parameters the probability is 0.9 that component 2 generated . It is not a hard label.

  2. 2. EM on gives variance 2.6667. Derive it.Answer

    Mean 4.0; squared deviations 4+0+4=8; MLE divides by 3. The unbiased 4.0 answers a different question.

  3. 3.Weights converge to on two overlapping groups. What do you conclude?Answer

    One component explains nearly everything. Try , check BIC, and consider that the small component fits outliers.

  4. 4.Full covariance on 50 points in 10 dimensions with . What breaks?Answer

    Each full covariance needs 55 parameters from about 10 effective points. Expect singularities; use tied or diag, regularize, or cut .

5

Practice

  • Deep-ML 341: Gaussian Mixture Model with EM Algorithm

    Problem 341: implement fit_gmm_1d with and steps for n_iterations, rounding means, variances and weights to 4 decimals

    Test one checks the closed form with means , variances and weights ; test two checks a symmetric case stays at means with variances . Derive both by hand first.

You're done when

You derive the numbers by hand, pass both Deep-ML tests, and can predict how tied versus full covariance changes the parameter count.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 6 more in the section

Also in this section

  • ISLP - Unsupervised LearningJames, Witten, Hastie, Tibshirani and Taylor · required

    Use Chapter 12 and its Python lab for the PCA derivations (12.2, including the low-rank approximation view and proportion of variance explained) and k-means (12.4.1), plus stability and interpretation limits, beside the notebook route.

  • Deep-ML - unsupervised problemsDeep-ML · support

    Use 17 K-Means Clustering, 19 PCA, 341 Gaussian Mixture Model with EM, 259 DBSCAN and 367 Isolation Forest as unit checks after the local implementation passes. Their tests were read in review; each card states what they pin, including the 367 path-length convention.

  • scikit-learn - preprocessing datascikit-learn · reference

    Read 8.3.1 standardization with the sparse with_mean=False rule, 8.3.1.3 scaling data with outliers, and 8.3.4 categorical encoding with handle_unknown, infrequent and sparse_output behavior. Apply after the HOML notebook build works.

  • scikit-learn - pipelines and composite estimatorsscikit-learn · reference

    Read 8.1.1 Pipeline chaining with the no-leakage rule and transformer caching, and 8.1.4 ColumnTransformer for heterogeneous columns with remainder and fitted-state behavior. Use it to assemble and serialize the feature-selection pipeline.

  • scikit-learn - imputation of missing valuesscikit-learn · reference

    Read 8.4.2 univariate median and most_frequent strategies, 8.4.6 Marking imputed values with MissingIndicator or add_indicator=True for missingness flags, and 8.4.7 estimators that accept NaN directly. Decide impute-only versus impute-plus-indicator per column.

  • UMAP - basic usage and parametersMcInnes, Healy and the UMAP contributors · reference

    Work the Penguin scaling and fit_transform section and the Digits fit and transform section, then read the parameters page for the n_neighbors local-global tradeoff and min_dist packing. Stay in 2D exploratory views with fixed seeds.