Prerequisite: ML | Binning or Discretization
Binning method is used to smoothing data or to handle noisy data. In this method, the data is first sorted and then the sorted values are distributed into a number of buckets or bins. As binning methods consult the neighborhood of values, they perform local smoothing.
There are three approaches to perform smoothing –
Smoothing by bin means : In smoothing by bin means, each value in a bin is replaced by the mean value of the bin.
Smoothing by bin median : In this method each bin value is replaced by its bin median value.
Smoothing by bin boundary : In smoothing by bin boundaries, the minimum and maximum values in a given bin are identified as the bin boundaries. Each bin value is then replaced by the closest boundary value.
- Sort the array of given data set.
- Divides the range into N intervals, each containing the approximately same number of samples(Equal-depth partitioning).
- Store mean/ median/ boundaries in each row.
Sorted data for price (in dollars): 4, 8, 9, 15, 21, 21, 24, 25, 26, 28, 29, 34 Smoothing by bin means: - Bin 1: 9, 9, 9, 9 - Bin 2: 23, 23, 23, 23 - Bin 3: 29, 29, 29, 29 Smoothing by bin boundaries: - Bin 1: 4, 4, 4, 15 - Bin 2: 21, 21, 25, 25 - Bin 3: 26, 26, 26, 34 Smoothing by bin median: - Bin 1: 9 9, 9, 9 - Bin 2: 24, 24, 24, 24 - Bin 3: 29, 29, 29, 29
Below is the Python implementation for above algorithm –
- Binning in Data Mining
- ML | Binning or Discretization
- Exploration with Hexagonal Binning and Contour Plots
- Python | Filtering data with Pandas .query() method
- Python | Data Augmentation
- Python for Data Science
- Python Data Types
- Working With JSON Data in Python
- Exploratory Data Analysis in Python | Set 2
- Python | Pandas Series.data
- Exploratory Data Analysis in Python | Set 1
- Exploratory Data Analysis in Python
- SQL using Python | Set 3 (Handling large data)
- Data Analysis and Visualization with Python | Set 2
- Inbuilt Data Structures in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.