# Chapter 12. Model Tuning and the Dangers of Overfitting

In order to use a model for prediction, the parameters for that model must be estimated. Some of these parameters can be estimated directly from the training data, but other parameters, called tuning parameters or hyperparameters, must be specified ahead of time and can’t be directly found from training data. These are unknown structural values or other kinds of values that have significant impact on the model but cannot be directly estimated from the data. This chapter will provide examples of tuning parameters and show how we use the tidymodels functions to create and handle tuning parameters. We’ll also demonstrate how poor choices of these values lead to overfitting and introduce several tactics for finding optimal tuning parameters values. Chapters 13 and 14 go into more detail on specific optimization methods for tuning.

# Model Parameters

In ordinary linear regression, there are two parameters $beta 0$ and $beta 1$ of the model:

${y}_{i}={\beta }_{0}+{\beta }_{1}{x}_{i}+{ϵ}_{i}$

When we have the outcome ($y$) and predictor ($x$) data, we can estimate the two parameters $beta 0$ and $beta 1$:

${\stackrel{^}{\beta }}_{1}=\frac{{\sum }_{i}\left({y}_{i}-\overline{y}\right)\left({x}_{i}-\overline{x}\right)}{{\sum }_{i}{\left({x}_{i}-\overline{x}\right)}^{2}}$

and

${\stackrel{^}{\beta }}_{0}=\overline{y}-{\stackrel{^}{\beta }}_{1}\overline{x}.$

We can directly estimate these values from the data for this example model because they are analytically tractable; if we have the data, then we can estimate these model parameters.

###### Note

There are many situations where a model has parameters that can’t be ...

Get Tidy Modeling with R now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.