sklearn.preprocessing.Binarizer() is a method which belongs to preprocessing module. It plays a key role in the discretization of continuous feature values.
A continuous data of pixels values of an 8-bit grayscale image have values ranging between 0 (black) and 255 (white) and one needs it to be black and white. So, using
Binarizer() one can set a threshold converting pixel values from 0 – 127 to 0 and 128 – 255 as 1.
One has a machine record having “Success Percentage” as a feature. These values are continuous ranging from 10% to 99% but a researcher simply wants to use this data for prediction of pass or fail status for the machine based on other given parameters.
threshold :[float, optional] Values less than or equal to threshold is mapped to 0, else to 1. By default threshold value is 0.0.
copy :[boolean, optional] If set to False, it avoids a copy. By default it is True.
Binarized Feature values
Download the dataset:
Go to the link and download Data.csv
Below is the Python code explaning sklearn.Binarizer()
Country Age Salary Purchased 0 France 44 72000 0 1 Spain 27 48000 1 2 Germany 30 54000 0 3 Spain 38 61000 0 4 Germany 40 1000 1 Original age data values : [44 27 30 38 40 35 78 48 50 37] Original salary data values : [72000 48000 54000 61000 1000 58000 52000 79000 83000 67000] Binarized age : [[1 0 0 1 1 0 1 1 1 1]] Binarized salary : [[1 0 0 0 0 0 0 1 1 1]]
- twitter-text-python (ttp) module - Python
- Python | pandas.map()
- Box-Cox Transformation using Python
- Multimethods in Python
- R vs Python in Datascience
- How to take screenshots using python?
- Polytopes in Python
- Python - sys.settrace()
- os.walk() in Python
- grp module in Python
- pwd module in Python
- Q-Learning in Python
- Python theHarvester - How to use it?
- Contingency Table in Python
- Exploring Correlation in Python
- Pylint module in Python
- Getopt module in Python
- Zulu module in Python
- Chi-square distance in Python
- Serialize Python dictionary to XML
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
Improved By : ManasChhabra2