시작하기무료로 시작하기

패널티 튜닝하기

Lasso가 모델의 특성 수를 줄이면서도 성능을 적절히 유지하는 합리적인 방법이라고 확신하여, 이제 가장 좋은 패널티 값을 선택해 모델을 튜닝하려고 해요. 기본 recipetraintest 분할이 환경에 로드되어 있어요.

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

R로 배우는 Feature Engineering

강의 보기

연습 안내

  • 패널티가 자동으로 튜닝되도록 모델을 설정하세요.
  • 30개의 레벨을 가지는 패널티 그리드를 구성하세요.

실습형 인터랙티브 연습

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

# Set up your model so that the penalty is tuned automatically
model_lasso_tuned <- logistic_reg() %>% set_engine("glmnet") %>%
  set_args(mixture = 1, ___ = ___) 
workflow_lasso_tuned <- workflow() %>%
  add_model(model_lasso_tuned) %>%
  add_recipe(recipe)

# Configure a penalty grid with 30 levels
penalty_grid <- grid_regular(penalty(range = c(-3, 1)), ___ = ___)

tune_output <- tune_grid(workflow_lasso_tuned,
  resamples = vfold_cv(train, v = 5),
  metrics = metric_set(roc_auc),grid = penalty_grid)

autoplot(tune_output)
코드 편집 및 실행