0

Подскажите, пожалуйста, как разбить данные на обучающую, валидационную и тестовую выборки в пропорции 60:20:20, сейчас получается так:

df_train, df_test = train_test_split(df, test_size=0.2, random_state=12345)
features_val, features_test, target_val, target_test = train_test_split(features, target, test_size=0.25, random_state=12345)

1 ответ 1

0

Ну, например, вот так:

df=pd.DataFrame({'A':[0,1,2,3,4,5,6,7,8,9],'B':[11,23,45,67,89,32,43,54,65,76]})
df_train, df_test1 =train_test_split(df, test_size=0.4, random_state=42)
df_test, df_val=train_test_split(df_test1, test_size=0.5, random_state=42)
print(df_train)
print(df_test)
print(df_val)

Результат:

   A   B
7  7  54
2  2  45
9  9  76
4  4  89
3  3  67
6  6  43

   A   B
8  8  65
5  5  32

   A   B
1  1  23
0  0  11

Как видите - пропорция 60:20:20, как просили.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.