R Tutorial: Background on modeling for prediction

DataCamp · Beginner ·🛠️ AI Tools & Apps ·6y ago
Skills: ML Pipelines70%

Key Takeaways

Introduces modeling for prediction using the tidyverse in R

Full Transcript

previously you were introduced to an example of modeling for explanation understanding what factors might explain teacher evaluation scores as given by students at the University of Texas Austin let's now consider an example of modeling for prediction the data set I'll use is the house sales in King County USA available at cackle comm it consists of homes sold near Seattle Washington in 2014 and 2015 I'll predict the sale price of houses based on their features such as size as measured by square feet of living space where one square foot is approximately 1/10 of a square meter condition number of bedrooms year built and whether it had a view of the waterfront just as with the evals data set I've included this data in the modern dive package which I preview using the glimpse function observe there are 21 thousand rows representing houses and 21 variables as before let's perform an exploratory data analysis or EDA of the outcome variable price recall the three approaches to EDA looking at the data visualizations and summary statistics since I've just done the first approach let's now visualize our data just as with the outcome variable score from our explanatory modeling example let's get a sense of the distribution of our new numerical outcome variable price using a histogram first let's look at the x axis tick marks since E Plus 0-6 means 10 to the 6 or 1 million we see that a majority of houses are less than 2 million dollars but why does the x axis stretch so far to the right it's because there are very number of houses with price closer to 8 million you say that the variable price is right skewed as exhibited by the long right tail this skew makes it difficult to compare prices of the less expensive houses recall that you saw something similar in the intro to the tidy verse course when visualizing the variable country population from the Gapminder dataset you visualize the relationship between countries life expectancies and populations using a scatterplot similar to this one because the populations of the two green dots corresponding to India and China were so large it was hard to study the relationship for less populated countries to remedy this you rescale the x axis to be on a log 10 scale now you can better distinguish points for countries with smaller populations furthermore horizontal intervals on the x-axis now correspond to multiplicative differences instead of additive ones for example distances between successive vertical white grid lines correspond to multiplicative increases by a factor of 10 now I'll do something similar where I log 10 transformed price using the mutate function to create a new variable log 10 price let's view the effects of this transformation on these two variables observe in particular the house in the sixth row with price 1.2 to 5 million since 10 to the 6 is 1 million it's log 10 price is six point zero 9 contrast this with all other houses with log 10 price less than 6 I'll treat log 10 price as our new outcome variable I can do this since log transformations are monotonic meaning they preserve orderings so if house aides price is lower than house B's then house a z' log10 price will also be lower than house bees log10 price let's take the earlier code to plot a histogram of the original outcome variable copy-paste and tweak the code to plot a histogram of the new log10 transformed outcome variable observe that after the transformation the distribution is much less skewed and in this case more symmetric and bell-shaped although this isn't always necessarily the case you can now better discriminate between houses at the lower end of the price scale now that you've seen a log transformation was warranted for the outcome variable price let's see if the predictor variable size as measured by the square feet of living space warrants a similar transformation

Original Description

Want to learn more? Take the full course at https://learn.datacamp.com/courses/modeling-with-data-in-the-tidyverse at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work. --- Previously, you were introduced to an example of modeling for explanation: understanding what factors might explain teacher evaluation scores as given by students at the University of Texas Austin. Now let's consider an example of modeling for prediction. The dataset I'll use is the "House Sales in King County USA" available at Kaggle.com. It consists of homes sold near Seattle Washington in 2014 & 2015. I'll predict the sale price of houses based on their features such as: -size as measured by sqfeet of living space, where 1 sqft is approximately 1/10th of a sqmeter -condition -number of bedrooms -year built -whether it had a view of the waterfront Just as with the evals dataset, I've included this data in the moderndive package, which I preview using the glimpse() function. Observe… there are 21k rows representing houses and 21 variables… As before, let's perform an exploratory data analysis, or EDA, of the outcome variable, price. Recall the three approaches to EDA: looking at the data, visualizations, and summary statistics. Since I've just done the first approach, let's now visualize our data. Just as with the outcome variable score from our explanatory modeling example, let's get a sense of the distribution of our new numerical outcome variable, price, using a histogram. First, let's look at the x-axis tick marks. Since e+06 means 10^6, or one million, we see that a majority of houses are less than 2 million dollars. But why does the x-axis stretch so far to the right? Its because there are a very small number of houses with price closer to 8 million. You say that the variable price is "right skewed" as exhibited by the long right tail. This skew makes it difficult to compare prices of the less expensive houses. Recall that you
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

Related Reads

📰
AI-Powered Change Logs: Automating Client Feedback for Small ArchViz Studios
Learn how AI-powered change logs can automate client feedback for small ArchViz studios, increasing efficiency and reducing manual labor
Dev.to AI
📰
Welcome to Day 6 of 100 Days of GenAI for DevOps!
Learn to debug Linux performance issues using CrewAI, a GenAI tool, and improve your DevOps skills
Medium · DevOps
📰
My AI Workflow for Turning Ideas Into Income (Templates Included)
Learn a 5-step AI workflow to turn ideas into income, including capturing ideas, validating with AI, building fast, automating marketing, and reviewing progress.
Medium · AI
📰
I Tested an AI Slop Detector — It Flagged My Own Writing
Learn how an AI slop detector flagged a writer's own content, highlighting the importance of unique writing styles and the potential of AI tools in content evaluation
Dev.to AI
Up next
How to Use Jotform AI App Builder (Step-by-Step Tutorial)
Kevin Stratvert
Watch →