Binning (also called discretization) converts continuous numeric features into discrete categories by dividing the value range into equal-width intervals. Each value is assigned to its corresponding bin. This technique can reduce noise, handle outliers, and make features compatible with algorithms that work better with categorical data.
Given a list of numeric values and a number of bins, assign each value to a bin index using equal-width binning.
The maximum value is clamped to the last bin. If all values are equal, all are assigned to bin 0.
Return one integer from zero through num_bins minus one for each value.
Input: values = [0, 25, 50, 75, 100], num_bins = 4
Output: [0, 1, 2, 3, 3]
Explanation: The width is 25, and the maximum is clamped into the final bin.
Input: values = [1, 2, 3, 4, 5, 6], num_bins = 2
Output: [0, 0, 0, 1, 1, 1]
Compute bin width from the observed minimum and maximum.
Convert each offset into an integer bin and clamp the maximum to the final index.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Binning (also called discretization) converts continuous numeric features into discrete categories by dividing the value range into equal-width intervals. Each value is assigned to its corresponding bin. This technique can reduce noise, handle outliers, and make features compatible with algorithms that work better with categorical data.
Given a list of numeric values and a number of bins, assign each value to a bin index using equal-width binning.
The maximum value is clamped to the last bin. If all values are equal, all are assigned to bin 0.
Return one integer from zero through num_bins minus one for each value.
Input: values = [0, 25, 50, 75, 100], num_bins = 4
Output: [0, 1, 2, 3, 3]
Explanation: The width is 25, and the maximum is clamped into the final bin.
Input: values = [1, 2, 3, 4, 5, 6], num_bins = 2
Output: [0, 0, 0, 1, 1, 1]
Compute bin width from the observed minimum and maximum.
Convert each offset into an integer bin and clamp the maximum to the final index.
Sign in to take notes on this problem
Accepts: array
Accepts: number