我在多变量线性回归中消除消除虚拟变量陷阱时收到以下错误

时间:2018-12-15 18:21:48

标签: python machine-learning linear-regression dummy-variable

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

1 个答案:

答案 0 :(得分:0)

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#F5FCFF',
    },
    header: {
        flex: 1,
        backgroundColor: '#e7fe52'
    },

    services: {
        flex: 4,
        backgroundColor: '#20fe23'
    },

    chart: {
        flex: 2,
        flexWrap: 'wrap',
        backgroundColor: '#4fccb0'
    }
});

您错过了那里的'()'。