finetune
에는 현재 tune
패키지에 있는 내용을 확장하는 모델 튜닝을 위한 몇 가지 추가 기능이 포함되어 있습니다. 다음 코드를 사용하여 패키지의 CRAN 버전을 설치할 수 있습니다.
install.packages( " finetune " )
패키지의 개발 버전을 설치하려면 다음을 실행하세요.
# install.packages("pak")
pak :: pak( " tidymodels/finetune " )
패키지에는 시뮬레이션 어닐링 과 레이싱이라는 두 가지 주요 도구 세트가 있습니다.
시뮬레이션된 어닐링 최적화를 통한 튜닝은 좋은 값을 찾기 위한 반복 검색 도구입니다.
library( tidymodels )
library( finetune )
# Syntax very similar to `tune_grid()` or `tune_bayes()`:
# # -----------------------------------------------------------------------------
data( two_class_dat , package = " modeldata " )
set.seed( 1 )
rs <- bootstraps( two_class_dat , times = 10 ) # more resamples usually needed
# Optimize a regularized discriminant analysis model
library( discrim )
rda_spec <-
discrim_regularized( frac_common_cov = tune(), frac_identity = tune()) % > %
set_engine( " klaR " )
# # -----------------------------------------------------------------------------
set.seed( 2 )
sa_res <-
rda_spec % > %
tune_sim_anneal( Class ~ . , resamples = rs , iter = 20 , initial = 4 )
# > Optimizing roc_auc
# > Initial best: 0.86480
# > 1 ♥ new best roc_auc=0.87327 (+/-0.004592)
# > 2 ♥ new best roc_auc=0.87915 (+/-0.003864)
# > 3 ◯ accept suboptimal roc_auc=0.87029 (+/-0.004994)
# > 4 + better suboptimal roc_auc=0.87171 (+/-0.004717)
# > 5 ◯ accept suboptimal roc_auc=0.86944 (+/-0.005081)
# > 6 ◯ accept suboptimal roc_auc=0.86812 (+/-0.0052)
# > 7 ♥ new best roc_auc=0.88172 (+/-0.003647)
# > 8 ◯ accept suboptimal roc_auc=0.87678 (+/-0.004276)
# > 9 ◯ accept suboptimal roc_auc=0.8627 (+/-0.005784)
# > 10 + better suboptimal roc_auc=0.87003 (+/-0.005106)
# > 11 + better suboptimal roc_auc=0.87088 (+/-0.004962)
# > 12 ◯ accept suboptimal roc_auc=0.86803 (+/-0.005195)
# > 13 ◯ accept suboptimal roc_auc=0.85294 (+/-0.006498)
# > 14 ─ discard suboptimal roc_auc=0.84689 (+/-0.006867)
# > 15 ✖ restart from best roc_auc=0.85021 (+/-0.006623)
# > 16 ◯ accept suboptimal roc_auc=0.87607 (+/-0.004318)
# > 17 ◯ accept suboptimal roc_auc=0.87245 (+/-0.004799)
# > 18 + better suboptimal roc_auc=0.87706 (+/-0.004131)
# > 19 ◯ accept suboptimal roc_auc=0.87213 (+/-0.004791)
# > 20 ◯ accept suboptimal roc_auc=0.86218 (+/-0.005773)
show_best( sa_res , metric = " roc_auc " , n = 2 )
# > # A tibble: 2 × 9
# > frac_common_cov frac_identity .metric .estimator mean n std_err .config
# > <dbl> <dbl> <chr> <chr> <dbl> <int> <dbl> <chr>
# > 1 0.308 0.0166 roc_auc binary 0.882 10 0.00365 Iter7
# > 2 0.121 0.0474 roc_auc binary 0.879 10 0.00386 Iter2
# > # ℹ 1 more variable: .iter <int>
두 번째 방법 세트는 경주 용입니다. 먼저 모든 그리드 포인트에 대해 작은 세트의 리샘플을 수행한 다음 통계적으로 테스트하여 어떤 포인트를 삭제하거나 더 조사해야 하는지 확인합니다. 여기서 두 가지 방법은 Kuhn(2014)의 방법을 기반으로 합니다.
예를 들어 ANOVA 유형 분석을 사용하여 매개변수 조합을 필터링합니다.
set.seed( 3 )
grid <-
rda_spec % > %
extract_parameter_set_dials() % > %
grid_max_entropy( size = 20 )
ctrl <- control_race( verbose_elim = TRUE )
set.seed( 4 )
grid_anova <-
rda_spec % > %
tune_race_anova( Class ~ . , resamples = rs , grid = grid , control = ctrl )
# > ℹ Evaluating against the initial 3 burn-in resamples.
# > ℹ Racing will maximize the roc_auc metric.
# > ℹ Resamples are analyzed in a random order.
# > ℹ Bootstrap10: 14 eliminated; 6 candidates remain.
# >
# > ℹ Bootstrap04: 2 eliminated; 4 candidates remain.
# >
# > ℹ Bootstrap03: All but one parameter combination were eliminated.
show_best( grid_anova , metric = " roc_auc " , n = 2 )
# > # A tibble: 1 × 8
# > frac_common_cov frac_identity .metric .estimator mean n std_err .config
# > <dbl> <dbl> <chr> <chr> <dbl> <int> <dbl> <chr>
# > 1 0.831 0.0207 roc_auc binary 0.881 10 0.00386 Preproce…
tune_race_win_loss()
도 사용할 수 있습니다. 이는 튜닝 매개변수를 토너먼트의 스포츠 팀으로 취급하고 승패 통계를 계산합니다.
set.seed( 4 )
grid_win_loss <-
rda_spec % > %
tune_race_win_loss( Class ~ . , resamples = rs , grid = grid , control = ctrl )
# > ℹ Racing will maximize the roc_auc metric.
# > ℹ Resamples are analyzed in a random order.
# > ℹ Bootstrap10: 3 eliminated; 17 candidates remain.
# >
# > ℹ Bootstrap04: 2 eliminated; 15 candidates remain.
# >
# > ℹ Bootstrap03: 2 eliminated; 13 candidates remain.
# >
# > ℹ Bootstrap01: 1 eliminated; 12 candidates remain.
# >
# > ℹ Bootstrap07: 1 eliminated; 11 candidates remain.
# >
# > ℹ Bootstrap05: 1 eliminated; 10 candidates remain.
# >
# > ℹ Bootstrap08: 1 eliminated; 9 candidates remain.
show_best( grid_win_loss , metric = " roc_auc " , n = 2 )
# > # A tibble: 2 × 8
# > frac_common_cov frac_identity .metric .estimator mean n std_err .config
# > <dbl> <dbl> <chr> <chr> <dbl> <int> <dbl> <chr>
# > 1 0.831 0.0207 roc_auc binary 0.881 10 0.00386 Preproce…
# > 2 0.119 0.0470 roc_auc binary 0.879 10 0.00387 Preproce…
이 프로젝트는 기여자 행동 강령과 함께 출시되었습니다. 이 프로젝트에 기여함으로써 귀하는 해당 조건을 준수하는 데 동의하게 됩니다.
tidymodels 패키지, 모델링, 머신러닝에 대한 질문과 토론은 Posit Community에 게시해 주세요.
버그가 발생했다고 생각되면 문제를 제출해 주세요.
어느 쪽이든, 코드에 대해 명확하게 전달하기 위해 표현(최소하고 재현 가능한 예제)을 만들고 공유하는 방법을 알아보세요.
tidymodels 패키지에 대한 기여 지침과 도움을 받는 방법에 대한 자세한 내용을 확인하세요.