参数 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 中的超参数调优

从简单开始:线性模型的参数

# 创建线性模型
linear_model <- lm(perimeter_worst ~ fractal_dimension_mean, data = breast_cancer_data)
# 获取系数
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 中的超参数调优

线性模型中的参数与超参数

  • 注意:模型参数在训练中被拟合(即被找到);它们是拟合或训练的结果。

  • 超参数在训练前设定。

  • 它们规定训练的方式。
args(lm)
help(lm)
?lm

linear_model <- lm(perimeter_worst ~ fractal_dimension_mean,
                   data = breast_cancer_data,
                   method = "qr")
R 中的超参数调优

机器学习中的参数 vs 超参数

在我们的线性模型中:

  • 系数在拟合时被求得。

 

  • method 是在拟合之前设定的选项。

在机器学习中,我们可能有:

  • 神经网络在训练中优化的权重和偏置 => 模型参数。
  • 学习率、权重衰减、随机森林的树数等可调选项 => 超参数。
R 中的超参数调优

为何要调超参数?

  • 虚拟橄榄球球员 ~ 超参数
  • 球员位置 ~ 超参数取值
  • 寻找最佳球员与位置组合 ~ 寻找超参数的最佳组合

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

R 中的超参数调优

让我们练习!

R 中的超参数调优

Preparing Video For Download...