train/test 데이터 나누기

정현준·2022년 11월 14일
0

특성과 타겟을 미리 나눈 경우

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(features, label, test_size=0.2, random_state=42)

특성과 타겟을 미리 나누지 않은 경우

from sklearn.model_selection import train_test_split

train, test = train_test_split(df, test_size=0.25, random_state=1)
# features 와 target 을 분리
target = 'target'
features = df.drop(columns=[target]).columns

X_train = train[features]
X_test = test[features]

y_train = train[target]
y_test = test[target]

0개의 댓글