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
  • What is your question? Commented Apr 7, 2020 at 12:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much, I am a beginner in Data Science, can you recommend any course for me?
paid : appliedaicourse, free: there are some youtube channel like krish naik's channel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.