홀드아웃 세트의 문제점

Python에서의 모델 검증

Kasey Jones

Data Scientist

전환 검증

전통적인 학습/테스트 분할은 전체 데이터의 대부분을 학습에, 작은 일부를 테스트에만 사용합니다.

X_train, X_val, y_train, y_val =
    train_test_split(X, y,
    test_size=0.2)

rf = RandomForestRegressor()

rf.fit(X_train, y_train)

out_of_sample = rf.predict(X_test) print(mae(y_test, out_of_sample))
10.24
Python에서의 모델 검증

전통적 학습 분할

cd = pd.read_csv("candy-data.csv")
s1 = cd.sample(60, random_state=1111)
s2 = cd.sample(60, random_state=1112)

겹치는 사탕:

print(len([i for i in s1.index if i in s2.index]))
39
Python에서의 모델 검증

전통적 학습 분할

초콜릿 사탕:

print(s1.chocolate.value_counts()[0])
print(s2.chocolate.value_counts()[0])
34
30
Python에서의 모델 검증

분할이 성능에 영향

샘플 1 테스트 오차

print('Testing error: {0:.2f}'.format(mae(s1_y_test, rfr.predict(s1_X_test))))
10.32

샘플 2 테스트 오차

print('Testing error: {0:.2f}'.format(mae(s2_y_test, rfr.predict(s2_X_test))))
11.56
Python에서의 모델 검증

Train, validation, test

X_temp, X_val, y_temp, y_val = train_test_split(..., random_state=1111)
X_train, X_test, y_train, y_test = train_test_split(..., random_state=1111)

rfr = RandomForestRegressor(n_estimators=25, random_state=1111, max_features=4)
rfr.fit(X_train, y_train)

print('Validation error: {0:.2f}'.format(mae(y_test, rfr.predict(X_test))))
9.18
print('Testing error: {0:.2f}'.format(mae(y_val, rfr.predict(X_val))))
8.98
Python에서의 모델 검증

라운드 2

X_temp, X_val, y_temp, y_val = train_test_split(..., random_state=1171)
X_train, X_test, y_train, y_test = train_test_split(..., random_state=1171)

rfr = RandomForestRegressor(n_estimators=25, random_state=1111, max_features=4)
rfr.fit(X_train, y_train)

print('Validation error: {0:.2f}'.format(mae(y_test, rfr.predict(X_test))))
8.73
print('Testing error: {0:.2f}'.format(mae(y_val, rfr.predict(X_val))))
10.91
Python에서의 모델 검증

홀드아웃 세트 연습

Python에서의 모델 검증

Preparing Video For Download...