【问题标题】:I am receiving the following error on eliminatng dummy variable trap in multivarible linear regression我在多变量线性回归中收到以下关于消除虚拟变量陷阱的错误
【发布时间】: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


    【解决方案1】:
    X=onehotencoder.fit_transform(X).toarray()
    

    你错过了那里的“()”。

    【讨论】:

      猜你喜欢
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 2019-01-25
      • 2018-05-29
      • 2020-11-30
      • 2018-11-14
      • 2018-11-16
      • 2020-11-25
      相关资源
      最近更新 更多