欢迎来到本课程

在 R 中使用 caret 的机器学习

Max Kuhn

Software Engineer at RStudio and creator of caret

监督学习

  • R caret
  • 自动化监督学习(又称预测建模)
  • 目标变量

一朵花和一张标注为"逾期"的发票图片。

在 R 中使用 caret 的机器学习

监督学习

  • 两类预测模型
    • 分类 ⇒ 定性
    • 回归 ⇒ 定量
  • 指标评估模型
    • 可量化
    • 客观
  • 回归使用均方根误差(RMSE)
在 R 中使用 caret 的机器学习

评估模型表现

  • 常见做法:计算样本内 RMSE
    • 过于乐观
    • 易导致过拟合
  • 更好:计算样本外误差(如 caret)
    • 模拟真实使用
    • 有助于避免过拟合
在 R 中使用 caret 的机器学习

样本内误差

# Fit a model to the mtcars data
data(mtcars)
model <- lm(mpg ~ hp, mtcars[1:20, ])
# Predict in-sample
predicted <- predict(
  model, mtcars[1:20, ], type = "response"
)
# Calculate RMSE
actual <- mtcars[1:20, "mpg"]
sqrt(mean((predicted - actual) ^ 2))
3.172132
在 R 中使用 caret 的机器学习

让我们来练习!

在 R 中使用 caret 的机器学习

Preparing Video For Download...