R Tutorial: Background on modeling for prediction
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
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
📰
📰
📰
📰
AI-Powered Change Logs: Automating Client Feedback for Small ArchViz Studios
Dev.to AI
Welcome to Day 6 of 100 Days of GenAI for DevOps!
Medium · DevOps
My AI Workflow for Turning Ideas Into Income (Templates Included)
Medium · AI
I Tested an AI Slop Detector — It Flagged My Own Writing
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI