A method to discretize numerical features by Python
- 2021-01-22 05:16:00
- OfStack
This is as follows:
data = np.random.randn(20)
factor = pd.cut(data,4)
pd.get_dummies(factor)
0 0 0 0 1
1 1 0 0 0
2 0 0 0 1
3 0 0 1 0
4 1 0 0 0
5 0 1 0 0
6 0 1 0 0
7 0 1 0 0
8 0 0 1 0
9 0 1 0 0
10 0 0 0 1
11 0 1 0 0
12 0 1 0 0
13 0 0 1 0
14 0 0 1 0
15 0 1 0 0
16 0 1 0 0
17 1 0 0 0
18 0 0 1 0
19 0 0 0 1
Where the 4 in the parameter indicates that, divided into 4 segments.