Chapter 6. Fitting Models with parsnip
The parsnip package is one of the R packages that is part of the tidymodels metapackage. It provides a fluent and standardized interface for a variety of different models. In this chapter, we give some motivation for why a common interface is beneficial for understanding and building models in practice and show how to use the parsnip package.
Specifically, we will focus on how to fit()
and predict()
directly with a
parsnip object, which may be a good fit for some straightforward modeling problems. Chapter 7 illustrates a better approach for many modeling tasks by combining models and preprocessors together into something called a workflow
object.
Create a Model
Once the data have been encoded in a format ready for a modeling algorithm, such as a numeric matrix, they can be used in the model building process.
Suppose that a linear regression model was our initial choice. This is equivalent to specifying that the outcome data are numeric and that the predictors are related to the outcome in terms of simple slopes and intercepts:
A variety of methods can be used to estimate the model parameters:
-
Ordinary linear regression uses the traditional method of least squares to solve for the model parameters.
-
Regularized linear regression adds a penalty to the least squares method to encourage simplicity by removing predictors and/or shrinking their coefficients toward zero. This can be executed ...
Get Tidy Modeling with R now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.