0

I am trying to train a machine learning model on a dataset using KFold. I keep getting this key error and don't know how to solve it. I have tried methods mentioned in How To Solve KeyError: u"None of [Index([..], dtype='object')] are in the [columns]" This is my code

diffFile = pd.read_csv('Difference.csv', delimiter=',', delim_whitespace= 0)
X = diffFile.iloc[:,[0,1,2]]
y = diffFile.iloc[:,3]
adb = AdaBoostClassifier()
scores = []
kf = KFold(n_splits=30)
for train_index,test_index in kf.split(X):
    X_train,X_test=X[train_index],X[test_index]
    y_train,y_test=y[train_index],y[test_index]
    adb.fit(X_train,y_train)
    scores.append(adb.score(X_test,y_test))

And this is my file https://drive.google.com/file/d/1_VwBNSADq6l893VFiULVPzrBYiB-fqyo/view?usp=sharing

I am using Jupyter Notebook with Python 3.7 Any help would be much appreciated. Thank You

1 Answers1

0

It should be:

X_train,X_test=X.iloc[train_index],X.iloc[test_index]
y_train,y_test=y.iloc[train_index],y.iloc[test_index]

you are trying to index the X using X[train_index] but you have pandas dataframe here.

Pygirl
  • 12,969
  • 5
  • 30
  • 43