차원 축소 후 정확도
차원 축소를 통해 과적합을 줄여 보겠습니다. 여기서는 다소 급진적인 방법으로, 성별을 구분하는 데 유용한 정보를 담고 있는 단일 열만 선택해 보려고 해요. 학습-검증 분할, 모델 학습, 예측 단계를 다시 수행해 학습 데이터와 테스트 데이터의 정확도를 비교해 보세요.
필요한 패키지와 y는 모두 미리 로드되어 있어요.
이 연습은 강의의 일부입니다
Python으로 배우는 차원 축소
연습 안내
ansur_df에서 목 둘레('neckcircumferencebase') 열만 선택하세요.- 데이터를 분할하고, 분류기를 생성해 학습시키세요. 이 부분은 이미 준비되어 있어요.
- 학습 세트와 테스트 세트 모두에 대해 정확도를 다시 계산하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Assign just the 'neckcircumferencebase' column from ansur_df to X
X = ansur_df[[____]]
# Split the data, instantiate a classifier and fit the data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
svc = SVC()
svc.fit(X_train, y_train)
# Calculate accuracy scores on both train and test data
accuracy_train = accuracy_score(____, svc.predict(____))
accuracy_test = accuracy_score(____, svc.predict(____))
print(f"{accuracy_test:.1%} accuracy on test set vs. {accuracy_train:.1%} on training set")