R Tutorial: Tidy your models with broom

DataCamp · Beginner ·🛠️ AI Tools & Apps ·6y ago
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 SQL Server Tutorial: Date manipulation
SQL Server Tutorial: Date manipulation
DataCamp
2 R Tutorial: Intermediate Interactive Data Visualization with plotly in R
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
3 R Tutorial: Adding aesthetics to represent a variable
R Tutorial: Adding aesthetics to represent a variable
DataCamp
4 R Tutorial: Moving Beyond Simple Interactivity
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
5 Python Tutorial: Why use ML for marketing? Strategies and use cases
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
6 Python Tutorial: Preparation for modeling
Python Tutorial: Preparation for modeling
DataCamp
7 Python Tutorial: Machine Learning modeling steps
Python Tutorial: Machine Learning modeling steps
DataCamp
8 R Tutorial: The prior model
R Tutorial: The prior model
DataCamp
9 R Tutorial: Data & the likelihood
R Tutorial: Data & the likelihood
DataCamp
10 R Tutorial: The posterior model
R Tutorial: The posterior model
DataCamp
11 R Tutorial: An Introduction to plotly
R Tutorial: An Introduction to plotly
DataCamp
12 R Tutorial: Plotting a single variable
R Tutorial: Plotting a single variable
DataCamp
13 R Tutorial: Bivariate graphics
R Tutorial: Bivariate graphics
DataCamp
14 Python Tutorial: Customer Segmentation in Python
Python Tutorial: Customer Segmentation in Python
DataCamp
15 Python Tutorial: Time cohorts
Python Tutorial: Time cohorts
DataCamp
16 Python Tutorial: Calculate cohort metrics
Python Tutorial: Calculate cohort metrics
DataCamp
17 Python Tutorial: Cohort analysis visualization
Python Tutorial: Cohort analysis visualization
DataCamp
18 R Tutorial: Building Dashboards with flexdashboard
R Tutorial: Building Dashboards with flexdashboard
DataCamp
19 R Tutorial: Anatomy of a flexdashboard
R Tutorial: Anatomy of a flexdashboard
DataCamp
20 R Tutorial: Layout basics
R Tutorial: Layout basics
DataCamp
21 R Tutorial: Advanced layouts
R Tutorial: Advanced layouts
DataCamp
22 Python Tutorial: Time Series Analysis in Python
Python Tutorial: Time Series Analysis in Python
DataCamp
23 Python Tutorial: Correlation of Two Time Series
Python Tutorial: Correlation of Two Time Series
DataCamp
24 Python Tutorial: Simple Linear Regressions
Python Tutorial: Simple Linear Regressions
DataCamp
25 Python Tutorial: Autocorrelation
Python Tutorial: Autocorrelation
DataCamp
26 R Tutorial: The gapminder dataset
R Tutorial: The gapminder dataset
DataCamp
27 R Tutorial: The filter verb
R Tutorial: The filter verb
DataCamp
28 R Tutorial: The arrange verb
R Tutorial: The arrange verb
DataCamp
29 R Tutorial: The mutate verb
R Tutorial: The mutate verb
DataCamp
30 R Tutorial: What is cluster analysis?
R Tutorial: What is cluster analysis?
DataCamp
31 R Tutorial: Distance between two observations
R Tutorial: Distance between two observations
DataCamp
32 R Tutorial: The importance of scale
R Tutorial: The importance of scale
DataCamp
33 R Tutorial: Measuring distance for categorical data
R Tutorial: Measuring distance for categorical data
DataCamp
34 Python Tutorial: Plotting multiple graphs
Python Tutorial: Plotting multiple graphs
DataCamp
35 Python Tutorial: Customizing axes
Python Tutorial: Customizing axes
DataCamp
36 Python Tutorial: Legends, annotations, & styles
Python Tutorial: Legends, annotations, & styles
DataCamp
37 Python Tutorial: Introduction to iterators
Python Tutorial: Introduction to iterators
DataCamp
38 Python Tutorial: Playing with iterators
Python Tutorial: Playing with iterators
DataCamp
39 Python Tutorial: Using iterators to load large files into memory
Python Tutorial: Using iterators to load large files into memory
DataCamp
40 SQL Tutorial: Introduction to Relational Databases in SQL
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
41 SQL Tutorial: Tables: At the core of every database
SQL Tutorial: Tables: At the core of every database
DataCamp
42 SQL Tutorial: Update your database as the structure changes
SQL Tutorial: Update your database as the structure changes
DataCamp
43 Python Tutorial: Classification-Tree Learning
Python Tutorial: Classification-Tree Learning
DataCamp
44 Python Tutorial: Decision-Tree for Classification
Python Tutorial: Decision-Tree for Classification
DataCamp
45 Python Tutorial: Decision-Tree for Regression
Python Tutorial: Decision-Tree for Regression
DataCamp
46 Python Tutorial: Census Subject Tables
Python Tutorial: Census Subject Tables
DataCamp
47 Python Tutorial: Census Geography
Python Tutorial: Census Geography
DataCamp
48 Python Tutorial: Using the Census API
Python Tutorial: Using the Census API
DataCamp
49 R Tutorial: A/B Testing in R
R Tutorial: A/B Testing in R
DataCamp
50 R Tutorial: Baseline Conversion Rates
R Tutorial: Baseline Conversion Rates
DataCamp
51 R Tutorial: Designing an Experiment - Power Analysis
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
52 R Tutorial: Introduction to qualitative data
R Tutorial: Introduction to qualitative data
DataCamp
53 R Tutorial: Understanding your qualitative variables
R Tutorial: Understanding your qualitative variables
DataCamp
54 R Tutorial: Making Better Plots
R Tutorial: Making Better Plots
DataCamp
55 SQL Tutorial: OLTP and OLAP
SQL Tutorial: OLTP and OLAP
DataCamp
56 SQL Tutorial: Storing data
SQL Tutorial: Storing data
DataCamp
57 SQL Tutorial: Database design
SQL Tutorial: Database design
DataCamp
58 Python Tutorial: Introduction to spaCy
Python Tutorial: Introduction to spaCy
DataCamp
59 Python Tutorial: Statistical Models
Python Tutorial: Statistical Models
DataCamp
60 Python Tutorial: Rule-based Matching
Python Tutorial: Rule-based Matching
DataCamp

This video teaches how to use the broom package in R to tidy machine learning models and extract useful information. The broom package provides three main functions: tidy, glance, and augment, which are used to extract conceptually different information from any model. By using these functions, you can easily extract model coefficients, statistics, and predicted values, and evaluate model fit.

Key Takeaways
  1. Load the broom package in R
  2. Create a linear model
  3. Use the tidy function to extract model coefficients and statistics
  4. Use the glance function to extract a one-row summary of the model
  5. Use the augment function to append predicted values to the original data
  6. Visualize model performance using the predicted and actual values
💡 The broom package provides a simple and efficient way to extract useful information from machine learning models, making it easier to evaluate and compare model performance.

Related Reads

📰
10 Ways Small Businesses Can Use AI To Grow–And Even Hire More Workers
Small businesses can leverage AI to boost sales and hire more workers, experts tell a House Committee
Forbes Innovation
📰
Beyond Connectivity: How Wi-Fi Is Becoming One of the World’s Largest Passive Sensor Networks
Wi-Fi is transforming into a massive passive sensor network, enabling innovative applications and use cases, and it's crucial to understand its potential and implications
Medium · AI
📰
Automating Form I-130 Drafting – Spouse, Parent, Spouse, Parent, Sibling, and Child Petitions Made Simple
Automate Form I-130 drafting using AI tools like the AI Validation Engine to streamline the petition process for spouses, parents, siblings, and children
Dev.to AI
📰
Every digital creator, developer, and marketer knows the silent frustration of the modern workflow…
Streamline your workflow by leveraging AI tools to automate tasks and increase productivity
Medium · AI
Up next
monday.com AI Review: What Works and What’s Just Hype? (Honest Take)
Mastering monday
Watch →