Quantile Binning

easy
Unit 4 · Preprocessing & Features0/3 to milestone

Implement QuantileBinner(n_bins):

  • fit(x): store the interior cut points np.quantile(x, [1/n, 2/n, ..., (n-1)/n])
  • transform(x): bin index 0 .. n_bins-1 for each value, where a value equal to a cut point goes to the upper bin (use np.searchsorted(..., side='right'))

Bins then hold roughly equal numbers of training points.

#preprocessing#discretization2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Quantile Binning · TechGradify