python - IndexError : index out of bounds -
i have implemented multinomialnb message. please me solve it. here code :
kf = kfold(len(x), n_folds=2, shuffle=true, random_state=9999) model_train_index = [] model_test_index = [] model = 0 k, (index_train, index_test) in enumerate(kf): x_train, x_test, y_train, y_test = x.ix[index_train,:], x.ix[index_test,:],y[index_train], y[index_test] clf = multinomialnb(alpha=0.1).fit(x_train, y_train) score = clf.score(x_test, y_test) f1score = f1_score(y_test, clf.predict(x_test)) precision = precision_score(y_test, clf.predict(x_test)) recall = recall_score(y_test, clf.predict(x_test)) print('model %d has accuracy %f | f1score: %f | precision: %f | recall : %f'%(k,score, f1score, precision, recall)) model_train_index.append(index_train) model_test_index.append(index_test) model+=1
and result :
indexerror traceback (most recent call last) <ipython-input-3-df0b24edb687> in <module>() 5 6 k, (index_train, index_test) in enumerate(kf): ----> 7 x_train, x_test, y_train, y_test = x.ix[index_train,:], x.ix[index_test,:],y[index_train], y[index_test] 8 clf = multinomialnb(alpha=0.1).fit(x_train, y_train) 9 score = clf.score(x_test, y_test) indexerror: index 100 out of bounds axis 0 size 100
python uses 0 based indexing if zeroth dimension of x.ix[index_train,:]
or y[index_train]
100, maximum value of index_train
valid 99. likewise index_test
.
something in
kf = kfold(len(x), n_folds=2, shuffle=true, random_state=9999)
is causing 1 of indices large 1 of arrays @ time enumerate(kf).
Comments
Post a Comment