我正在为 MachineLearning 使用 udemy 课程,我正在尝试为我的变量形成一个虚拟变量,列是 Country
我想换成法国 德国 西班牙
- France 1 0 0
- Spain 0 0 1
- Germany 0 1 0 etc
我试过了,但我得到了这个错误
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X = LabelEncoder()
X[:, 0] = labelencoder_X.fit_transform(X[:, 0])
onehotencoder = OneHotEncoder(categorical_values = [0])
X = onehotencoder.fit_transform(X).toarray()
Traceback (most recent call last):
File "<ipython-input-9-f7654080cf6a>", line 4, in <module>
onehotencoder = OneHotEncoder(categorical_values = [0])
TypeError: __init__() got an unexpected keyword argument 'categorical_values'