Today we will cover how we can take a simple data set and create a predictive model for a property based solely on the square footage.
2024-03-08
Today we will cover how we can take a simple data set and create a predictive model for a property based solely on the square footage.
Importing the Data set + Identify your IV & DV
Plot the imported data onto a basic scatterplot
Credit: Data set is from https://medium.com/found-it/housing-price-prediction-using-r-899bcbdf1b
We are iteratively fitting a linear equation to the scattered data. This allows us to model the previously disconnected data with a mathematical equation \[ y = mx + c \]
where:
Begin by taking the LoBF calculated in the previous slide. \[ y = 462x + 2387308.5 \] we can then insert a hypothetical square footage. Let’s choose 14,000.
\[ y = 462(14000) + 2387308.5 \] \[ y = 8,855,308.50 \]
We can take the visualization one step further using plotly.
library(plotly)
## Create the Scatter Plot
plot <- plot_ly(housing, x = ~area, y = ~price,
type = 'scatter', mode = 'markers')
## Add the LoBF
plot <- add_lines(plot, x = ~area,
y = ~fitted(lm(price ~ area, housing)),
name = "Predictive Model")
## Create additional customization/labels
plot <- layout(plot, title = "Square Footage vs. Price",
xaxis = list(title = "Square Footage"),
yaxis = list(title = "Price in $"))
plot