【发布时间】:2019-05-16 16:26:43
【问题描述】:
dataset = pd.read_csv('50_Startups.csv')
X = dataset.iloc[: , :-1].values
y = dataset.iloc[:,4].values
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X = LabelEncoder()
X[:,3] = labelencoder_X.fit_transform(X[:,3])
onehotencoder = OneHotEncoder(categorical_features = [3])
X=onehotencoder.fit_transform(X).toarray
# Avoiding the Dummy Variable Trap
X=X[:, 1:]
编写上述代码时出现以下错误。请您提出修改建议
File "<ipython-input-35-9ad621cd0c86>", line 13, in <module>
X=X[:, 1:]
TypeError: 'method' object is not subscriptable
【问题讨论】:
标签: python machine-learning linear-regression dummy-variable