简体   繁体   中英

KFold cross validation on a pandas dataframe

I have a dataset that looks like this在此处输入图片说明

Im trying to run a 10-fold cross-validation on the set. However, Im encountering this error在此处输入图片说明 error - raise KeyError(f"None of [{key}] are in the [{axis_name}]") KeyError: "None of [Int64Index([ 578, 579, 580, 581, 582, 583, 584, 585, 586, 587,\\n ...\\n 5770, 5771, 5772, 5773, 5774, 5775, 5776, 5777, 5778, 5779],\\n dtype='int64', length=5202)] are in the [columns]"

How do I solve this?

The variables train and test are row indices, so you will probably solve it by replacing the last row with

X_train, X_test, y_train, y_test = X.iloc[train], X.iloc[test], Y.iloc[train], Y.iloc[test]

(Please next time don't post your code as an image and report the whole error message.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM