How to resolve “IndexError: too many indices for array”

560    Asked by ElizabethClark in Data Science , Asked on Jul 15, 2021

 My code below is giving me the following error "IndexError: too many indices for array". I am quite new to machine learning so I do not have any idea about how to solve this. Any kind of help would be appreciated.

train = pandas.read_csv("D:/...input/train.csv")
xTrain = train.iloc[:,0:54]
yTrain = train.iloc[:,54:]
from sklearn.cross_validation import cross_val_score
clf = LogisticRegression(multi_class='multinomial')
scores = cross_val_score(clf, xTrain, yTrain, cv=10, scoring='accuracy')
print('****Results****')
print(scores.mean())

Answered by Claudine Tippins

To solve too many indices for array python you should go through the below solutions. Here, you have declared contents for your array that don't fit it. There is no declaration of your array. If we assume it to be one dimensional and the program is opposing treating it like a 2 dimensional.

So, check your declarations whether they are correct or not and also test the code by printing the values after you've set them to double check they are what you intend them to be.



Your Answer

Interviews

Parent Categories