I will write it as my memorandum.
It's very pinpoint from the first article, but as a feature engineering of machine learning,
・ 0 ~ 1 is 1,1 ~ 3 is 2 ・ 3 ~ 10 is 3 ・ 10 ~ 20 is 4 …………
I think there are times when you want to classify features.
A very easy-to-understand example [Beaufort scale](https://ja.wikipedia.org/wiki/Beaufort scale)
python
beaufort = [(0, 0, 0.3), (1, 0.3, 1.6), (2, 1.6, 3.4), (3, 3.4, 5.5), (4, 5.5, 8), (5, 8, 10.8), (6, 10.8, 13.9),
(7, 13.9, 17.2), (8, 17.2, 20.8), (9, 20.8, 24.5), (10, 24.5, 28.5), (11, 28.5, 33), (12, 33, 200)]
for item in beaufort:
train.loc[(train['wind_speed']>=item[1]) & (train['wind_speed']<item[2]), 'beaufort_scale'] = item[0]
This sample code is very simple, powerful and easy to use, Put it in your drawer! !!
Recommended Posts