Python:IndexError:数组的索引太多了

时间:2016-06-05 01:30:53

标签: python python-2.7 python-3.x indexing

以下代码在运行时抛出错误:

model_ridge = lm.LogisticRegression(penalty='l2', dual=False, tol=0.0001, C=9081)
model_randomforest = RandomForestClassifier(n_estimators = 200)
pred_ridge = []
pred_randomforest = []
new_Y = []
for i in range(10):
    indxs = np.arange(i, X.shape[0], 10)
    indxs_to_fit = list(set(range(X.shape[0])) - set(np.arange(i, X.shape[0], 10)))
    pred_ridge = pred_ridge + list(model_ridge.fit(X[indxs_to_fit,:1], y[indxs_to_fit,:1]).predict_proba(X[indxs,:1])[:,1])
    pred_randomforest = pred_randomforest + list(model_randomforest.fit(X[indxs_to_fit,:], y[indxs_to_fit,:]).predict_proba(X[indxs,:])[:,1])
    new_Y = new_Y + list(y[indxs,:])

这是错误:

line 159, in <module>
pred_ridge = pred_ridge + list(model_ridge.fit(X[indxs_to_fit,:1], y[indxs_to_fit,:1]).predict_proba(X[indxs,:1])[:,1])
IndexError: too many indices for array

我无法理解发生了什么,请你帮我弄清楚我做错了什么?

0 个答案:

没有答案