R Tutorial: Tidy your models with broom
Skills:
ML Pipelines70%
Key Takeaways
This video demonstrates the use of the broom package in R to tidy machine learning models, specifically linear models, and extract useful information such as coefficients, statistics, and predicted values. The broom package provides three main functions: tidy, glance, and augment, which are used to extract conceptually different information from any model.
Full Transcript
now that you know how to work with list columns in a tidy manner you can begin to work with the tools you need to explore and evaluate machine learning models as you can probably imagine the bulk of the work of machine learning resides in step two of this workflow since you can store complex model objects in your data frame you can also work with these objects using the tools available in various our packages in this video we will focus on the broom package a package designed to convert useful model outputs into tidy data frames the core of broom is encapsulated by three functions which aim to extract conceptually different information from any model tidy is used to extract the statistical findings of a model Glantz provides a one row summary of a model and augment appends the predicted values of a model to the data being modeled let's explore each of these in greater detail by reviewing the results of the linear model that you created for Algeria if you look at the summary of the Algeria model you can see that there is a lot of useful information here however this information is not particularly easy to extract directly from the object as it is to simply print it but using tidy and glance you can easily extract this information into data frames the tidy function collects the statistical findings of a model into a data frame when used with a linear model Tidy returns the coefficients and their corresponding statistics for that model to extract these statistics you simply apply the tidy function to the model object as shown here the next broom function glance is used to return a one rule summary of a model for a linear model this summary contains various statistics about the fit of the model such as the r-squared it drafting this information into a data frame is as simple as calling the function on the model object finally the augment function builds an observation level data frame containing the original data used to build the model as well as the predicted value for each observation as the column dot fitted furthermore augment appends model specific statistics of fit for each observation by constructing a data frame containing both the original values and those predicted by our model you can explore the fit of the model for instance you can visualize how well your model fits the data by plotting the predicted and actual values of life expectancy with respect to year in this plot the actual values are the black points and the fit of the model or predicted values is shown as the red line by examining this plot you can learn that a simple linear model may not be the best approach for this example and you would consider either including more features or using a nonlinear approach to better capture this relationship using these three tools makes it easy to extract model coefficients fit statistics and observation level performance for many different machine learning models in Chapter two we will use broom as a part of the list column workflow to do this for all 77 of our country level models with just a few lines of code but first let's review what you have learned with a few exercises
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/machine-learning-in-the-tidyverse at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Now that you know how to work with list columns in a tidy manner you can begin to work with the tools you need to explore and evaluate machine learning models.
As you can probably imagine, the bulk of the work of machine learning resides in step two of this workflow. Since you can store complex model objects in your dataframe you can also work with these objects using the tools available in various R packages.
In this video, we will focus on the broom package. A package designed to convert useful model outputs into tidy dataframes.
The core of broom is encapsulated by three functions which aim to extract conceptually different information from any model.
- tidy() is used to extract the statistical findings of a model.
- glance() provides a one row summary of a model, and
- augmment() appends the predicted values of a model to the data being modeled.
Let's explore each of these in greater detail by reviewing the results of the linear model that you created for Algeria.
If you look at the summary() of the Algeria model you can see that there is a lot of useful information here. However, this information is not particularly easy to extract directly from the object as it is to simply print it. But using tidy() and glance() you can easily extract this information into dataframes.
The tidy() function collects the statistical findings of a model into a dataframe.
When used with a linear model, tidy() returns the coefficients and their corresponding statistics for that model.
To extract these statistics you simply apply the tidy() function to the model object as shown here.
The next broom function, glance(), is used to return a one row summary of a model.
For a linear model, this summary contains various statistics about the fit of the
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: ML Pipelines
View skill →Related Reads
📰
📰
📰
📰
10 Ways Small Businesses Can Use AI To Grow–And Even Hire More Workers
Forbes Innovation
Beyond Connectivity: How Wi-Fi Is Becoming One of the World’s Largest Passive Sensor Networks
Medium · AI
Automating Form I-130 Drafting – Spouse, Parent, Spouse, Parent, Sibling, and Child Petitions Made Simple
Dev.to AI
Every digital creator, developer, and marketer knows the silent frustration of the modern workflow…
Medium · AI
🎓
Tutor Explanation
DeepCamp AI