当我尝试使用Python 3.67使用OnehotEncoder
将编码的标签转换为数组时遇到问题。
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
dataset = pd.read_csv('crime.csv')
X = dataset.sample(1000)
X.dropna()
x= X.loc[:,dataset.columns != 'IS_CRIME'].values
#Displaying content of the categorical variable
a = X.iloc[:,16]
#Encoding
labelencoder_X = LabelEncoder()
x[:, 16] = labelencoder_X.fit_transform(x[:, 16])
onehotencoder = OneHotEncoder(categorical_features = [0])
x = onehotencoder.fit_transform(x).toarray()