离散 feature 的 encoding 分为两种情况:
1、离散 feature 的取值之间没有大小的意义,比如color:[red,blue],那么就使用 one-hot encoding
2、离散 feature 的取值有大小的意义,比如size:[X,XL,XXL],那么就使用数值的映射{X:1,XL:2,XXL:3}
In [90]:
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
np.set_printoptions(precision=4)
…
In [91]:
df = pd.DataFrame([
['green', 'M', 10.1, 'class1'],
['red', 'L', 13.5, 'class2'],
['blue', 'XL', 15.3, 'class1']])
df.columns = ['color', 'size', 'prize', 'class label']
df
Out[91]:
…
In [92]: