-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClass5-multiple-regression-analysis.R
More file actions
53 lines (43 loc) · 1.09 KB
/
Class5-multiple-regression-analysis.R
File metadata and controls
53 lines (43 loc) · 1.09 KB
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
library(tidyverse)
# read csv
df_toys <- read.csv("ToySalesComplete.csv")
# data wrangling
# scatter plot to check relation between features
# and target variables
# Price and UnitSales
df_toys %>%
ggplot(aes(Price, UnitSales)) +
geom_point() +
geom_smooth(method="lm")
# Adexp and UnitSales
df_toys %>%
ggplot(aes(Adexp, UnitSales)) +
geom_point() +
geom_smooth(method="lm")
# Promexp and UnitSales
df_toys %>%
ggplot(aes(Promexp, UnitSales)) +
geom_point() +
geom_smooth(method="lm")
# split the dataset
set.seed(1)
df_toys$id <- 1:nrow(df_toys)
train <- df_toys %>% sample_frac(0.80)
test <- anti_join(df_toys, train_toys,
by="id")
# train the model
model <- lm (UnitSales ~ Price +
Adexp +
Promexp,
data = train)
summary(model)
# test the model
test$predicted_values <- predict(model, test)
view(test)
# calculate the error
error <- sqrt(mean(((test$UnitSales) -
(test$predicted_values))^2))
print(error)
# Class Activity
view(mtcars)
?mtcars