강의

멘토링

로드맵

Inflearn Community Q&A

gg787001952's profile image
gg787001952

asked

[Revised Edition] The Complete Guide to Python Machine Learning

선생님 kfold 질문있습니다.

Written on

·

247

0

강의 너무 잘듣고 있습니다 항상 감사드립니다. 

kfold 로 데이터나눌때 데이터프레임으로 변환하고 데이터를 넣으니까 이런오류가 뜨는데 어떻게 해야하나요??

kfold뒤 매개변수에 데이터프레임은 안되고 numpy 형태만 가능한가요??

자세한 설명 부탁드립니다 ㅠㅠ 

머신러닝 배워볼래요? python통계

Answer 1

1

dooleyz3525님의 프로필 이미지
dooleyz3525
Instructor

안녕하십니까, 

아마도 iloc등으로 찾지 않아서 오류가 나오는 것 같습니다. 

아래와 같이 수정해 보시지요. 

iris_data = load_iris()

iris_df = pd.DataFrame(iris_data.data, columns=iris_data.feature_names)

label_df = pd.DataFrame(iris_data.target, columns=['target'])

for train_index, test_index  in kfold.split(iris_df):

    #print(train_index, test_index)

    X_train, X_test = iris_df.iloc[train_index], iris_df.iloc[test_index]

    y_train, y_test = label_df.iloc[train_index], label_df.iloc[test_index]

    print('#### features:\n', X_train.iloc[0], '\n#### target:', y_train.iloc[0])

gg787001952's profile image
gg787001952

asked

Ask a question