仅整数,切片(`:`),省略号(`...`),numpy.newaxis(`None`)和整数或布尔数组有效

时间:2019-05-09 04:11:37

标签: python deep-learning artificial-intelligence classification decision-tree

我已经从数据集中选择了要素,然后当我尝试从数据集中选择那些要素时,出现此错误。为什么会这样?

    dataset = pd.read_csv('Banking Dataset.csv')
    LabelEncoder1 = LabelEncoder()
    independent_variables[:,1] = LabelEncoder1.fit_transform(independent_variables[:,1])
    LabelEncoder2 = LabelEncoder()
    independent_variables[:,2] = LabelEncoder2.fit_transform(independent_variables[:,2])


    onehotencoder = OneHotEncoder(categorical_features=[1])
    independent_variables = onehotencoder.fit_transform(independent_variables).toarray()

    X_train, X_test, Y_train,Y_test = train_test_split(independent_variables,target_values  ,test_size=0.25,random_state=0)

    c = DecisionTreeClassifier(min_samples_split=100)
    features =["CreditScore","Geography","Gender","Age","Tenure","Balance","NumOfProducts","HasCrCard","IsActiveMember","EstimatedSalary"]
    X = X_train(features)

输出:

FutureWarning:不建议使用非元组序列进行多维索引编制;使用arr[tuple(seq)]而不是arr[seq]。将来,它将被解释为数组索引arr[np.array(seq)],它将导致错误或不同的结果。   X_train = X_train [功能] 追溯(最近一次通话):

X_train=X_train[features]

IndexError:只有整数,切片(:),省略号(...),numpy.newaxis(None)和整数或布尔数组都是有效索引

Process finished with exit code 1

2 个答案:

答案 0 :(得分:3)

使用以下

X=X_train[features]

代替

X=X_train(features)

调用numpy数组时使用[]

答案 1 :(得分:0)

错误代码说的是具体行

X=X_train(features)

应该在()的特征周围有方括号[]。即

X=X_train[features]