參數 vs 超參數

R 的超參數調校

Dr. Shirin Elsinghorst

Senior Data Scientist

關於我

R 的超參數調校

「超」參數 vs 模型參數

  • 先看一個範例資料集:
head(breast_cancer_data)
# A tibble: 6 x 11
  diagnosis concavity_mean symmetry_mean fractal_dimension perimeter_se smoothness_se
  <chr>              <dbl>         <dbl>             <dbl>        <dbl>         <dbl>
1 M                 0.300          0.242            0.0787         8.59       0.00640
2 M                 0.0869         0.181            0.0567         3.40       0.00522
3 M                 0.197          0.207            0.0600         4.58       0.00615
4 M                 0.241          0.260            0.0974         3.44       0.00911
  • 接著建立一個簡單的線性模型
R 的超參數調校

從簡入手:線性模型中的模型參數

# Create linear model
linear_model <- lm(perimeter_worst ~ fractal_dimension_mean, data = breast_cancer_data)
# Get coefficients
summary(linear_model)$coefficients
                       Estimate Std. Error t value Pr(>|t|)    
(Intercept)              167.60      25.91   6.469  3.9e-09 ***
fractal_dimension_mean  -926.39     392.86  -2.358   0.0204 *
R 的超參數調校

從簡入手:線性模型中的模型參數

  • 模型參數是在訓練期間擬合(也就是找出)的。
  • 它們是模型擬合或訓練的結果

  • 在线性模型中,我們要找的是係數

linear_model$coefficients
(Intercept) fractal_dimension_mean 
   167.5972              -926.3866 
  • 你可以把它們視為模型的斜率截距
R 的超參數調校

線性模型中的係數

ggp <- ggplot(data = breast_cancer_data, 
              aes(x = fractal_dimension_mean, y = perimeter_worst)) +
        geom_point(color = "grey")

ggp + geom_abline(slope = linear_model$coefficients[2], intercept = linear_model$coefficients[1])

R 的超參數調校

線性模型中的模型參數 vs 超參數

  • 提醒你:模型參數是在訓練期間擬合(也就是找出)的;它們是模型擬合或訓練的結果

  • 超參數是在訓練前設定的。

  • 它們用來指定訓練要如何進行。
args(lm)
help(lm)
?lm

linear_model <- lm(perimeter_worst ~ fractal_dimension_mean,
                   data = breast_cancer_data,
                   method = "qr")
R 的超參數調校

機器學習中的參數 vs 超參數

在我們的線性模型中:

  • 係數是在擬合時被找出的。

 

  • method 是在擬合之前可設定的選項。

機器學習中可能有:

  • 在訓練中被最佳化的神經網路權重與偏差 ⇒ 模型參數
  • 可調整的選項,如 learning rate、weight decay,以及 Random Forest 中的樹數 ⇒ 超參數
R 的超參數調校

為何要調超參數?

  • 幻想足球球員 ~ 超參數
  • 球員所打的位置 ~ 超參數的數值
  • 找到球員與位置的最佳組合 ~ 找到超參數的最佳組合

https://pixabay.com/photo-1493087/

R 的超參數調校

一起來練習吧!

R 的超參數調校

Preparing Video For Download...