Skip to content
truthxify
← Journal

Phase 2 — Classical ML

June 1, 2026

Continue the course 3 of the Machine Learning Specialization(Anomaly Detection)

What I Did

Implemented a anomaly detection algorithm

What I Learned

Anomaly detection looks at unlabeled dataset of normal examples, learns what normal looks like, then flags new examples that looks different

We basically use density estimation to figure out which ones are anomalous and which ones are not

To do density estimation, we use the Gaussian distribution where the probability pp is:

p(x)=12πσe(xμ)22σ2p(x) = {\frac{1}{\sqrt{2\pi}\sigma}}e^{-\frac{(x-\mu)^2}{2{\sigma}^2}}

For the anomaly detection algorithm, we do the following:

  • Choose n features, each one xjx_j where j=1,2,...,nj=1,2,...,n
  • Fit parameters μ1,μ2,...,μn,σ12,σ22,...,σn2\mu_1, \mu_2, ..., \mu_n, \sigma_1^2, \sigma_2^2, ..., \sigma_n^2
μj=1mi=1mxj(i),  σj2=1mi=1m(xj(i)μj)2\mu_j = \frac{1}{m}\sum_{i=1}^mx_j^{(i)}, \ \ \sigma_j^2 = \frac{1}{m}\sum_{i=1}^m(x_j^{(i)} - \mu_j)^2
  • Given a new example x, we compute:
p(x)=j=1n12πσje(xjμj)22σj2p(x) =\prod_{j=1}^n {\frac{1}{\sqrt{2\pi}\sigma_j}}e^{-\frac{(x_j-\mu_j)^2}{2{\sigma_j}^2}}
  • Flag as anomalous if p(x)<ϵp(x) < \epsilon

We can evaluate the anomaly detection using a cross validation and testing set with labeled examples

We can also choose to use anomaly detection or supervised learning based on the problem we are trying to solve and what they of dataset is available to use.

Anomaly detection works best for fraud detection, manufacturing defects detection and monitoring machines in a data center while supervised learning works well for spam classification, weather prediction and disease classification

Bugs & Blockers

N/A

Concepts That Need More Time

N/A

Tomorrow

Continue the course 3 of the Machine Learning Specialization(Recommenders)

Wins

Implemented a anomaly detection algorithm