시작하기무료로 시작하기

정규화 강도 조정하기

현재 Lasso 모델의 \(R^2\) 점수는 84.7%입니다. 정규화가 지나치게 강하면 편향이 커져 예측 성능이 떨어질 수 있어요.

alpha 매개변수를 조정해 예측 성능과 모델 단순성 사이의 균형을 개선해 봅시다.

이 연습은 강의의 일부입니다

Python으로 배우는 차원 축소

강의 보기

연습 안내

  • 다음 옵션 1, 0.5, 0.1, 0.01 중에서, \(R^2\) 값이 98%를 넘는 조건을 만족하는 alpha의 값 가운데 가장 큰 값을 찾으세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Find the highest alpha value with R-squared above 98%
la = Lasso(____, random_state=0)

# Fits the model and calculates performance stats
la.fit(X_train_std, y_train)
r_squared = la.score(X_test_std, y_test)
n_ignored_features = sum(la.coef_ == 0)

# Print peformance stats 
print(f"The model can predict {r_squared:.1%} of the variance in the test set.")
print(f"{n_ignored_features} out of {len(la.coef_)} features were ignored.")
코드 편집 및 실행