Feature Selection with Mutual Information

easy
Unit 6 · Kernels0/3 to milestone

Mutual information measures how much knowing a feature reduces uncertainty about the label. Unlike correlation, it catches non-linear relationships.

For discrete arrays: I(X;Y)=∑x,yp(x,y) ln⁡p(x,y)p(x) p(y)I(X; Y) = \sum_{x, y} p(x, y)\,\ln\frac{p(x, y)}{p(x)\,p(y)} (in nats), using empirical frequencies and skipping zero cells.

Implement:

  • entropy(x): −∑pln⁡p-\sum p \ln p
  • mutual_information(x, y)
  • select_k_best(X, y, k): the indices of the k columns with the highest MI with y, best first (ties: lower index)
#feature-selection#information-theory2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Feature Selection with Mutual Information · TechGradify