Home ch5. Category Data
Post
Cancel

ch5. Category Data

Summary


Category data를 machine learning에 알맞은 feature로 변환하는 다양한 전략을 알아봅니다.

  • Category Data Encoding
1
2
3
4
5
6
7
8
9
10
# sklearn의 LabelBinarizer 사용 one-hot encoding: 순서가 없는 category data feature를 encoding 합니다. (5.1)
one_hot = LabelBinarizer()
one_hot.fit_transform(feature)

# dataframe의 replace 사용: 순서가 있는 category data feature를 encoding 합니다. String label을 numeric type으로 변환합니다. (5.2)
scale_mapper = {'Low': 1, 'Medium': 2, 'High':3}
dataframe['Score'].replace(scale_mapper)

# sklearn의 DictVectorizer 사용: Feature dictionary를 encoding 합니다. Sparse matrix를 return 합니다. (5.3)
dictvectorizer.fit_transform(dictionary)



  • Null Value 대체하기 (5.4)
1
2
3
# KNN classifier 사용: ML classification algorithm을 훈련하여 null value를 예측합니다.

# sklearn의 SimpleImputer 사용: null value를 feature에서 가장 자주 등장하는 value로 채웁니다.



  • Class Imvalence 다루기 (5.5)
1
2
3
4
5
6
7
# 더 많은 data를 수집합니다.

# 불가능하다면 model evaluation 지표를 변경합니다. Accuracy보다 precision, recall, F1-measutr, ROC curve 등이 있습니다.

# 잘 동작하지 않으면 class weight를 사용합니다.

# 혹은 down-sampling or up-sampling을 고려합니다.



Practice


Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This post is licensed under CC BY 4.0 by the author.