-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSLR Salary_Data.R
90 lines (56 loc) · 1.79 KB
/
SLR Salary_Data.R
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#Salary_hike -> Build a prediction model for Salary_hike
Salary_hike <- read.csv("~/Downloads/Data Science/data set/Salary_Data.csv")
summary(Salary_hike)
attach(Salary_hike)
var(Salary_hike$YearsExperience)
sd(Salary_hike$YearsExperience)
var(Salary_hike$Salary)
sd(Salary_hike$Salary)
plot(YearsExperience,Salary)
boxplot(Salary_hike)
hist(YearsExperience)
hist(Salary)
summary(Salary_hike)
ye<- YearsExperience
sh <- Salary
cor(ye,sh)
reg<-lm(sh~ye)
summary(reg)
confint(reg,level = 0.95)
predict(reg,interval="predict")
reg_log<-lm(sh~log(ye))
summary(reg_log)
confint(reg_log,level=0.95)
predict(reg_log,interval="predict")
reg_exp<-lm(log(sh)~ye)
summary(reg_exp)
exp(predict(reg_exp,interval="predict"))
Salary_hike[,"ye_sq"] = ye*ye
quad_mod <- lm(sh~ye+I(ye^2))
summary(quad_mod)
confint(quad_mod,level=0.95)
predict(quad_mod,interval="predict")
qd_model <- lm(sh~ye+ye_sq)
summary(qd_model)
confint(quad_mod,level=0.95)
predict(quad_mod,interval="predict")
poly_mod <- lm(sh~ye+I(ye^2)+I(ye^3))
summary(poly_mod)
confint(poly_mod,level=0.95)
predict(poly_mod,interval="predict")
model_R_Squared_values <- list(model=NULL,R_squared=NULL)
model_R_Squared_values[["model"]] <- c("reg","reg_log","reg_exp","quad_mod","poly_mod")
model_R_Squared_values[["R_squared"]] <- c(0.9554,0.8487,0.9295,0.9538,0.9594)
Final <- cbind(model_R_Squared_values[["model"]],model_R_Squared_values[["R_squared"]])
View(model_R_Squared_values)
predicted_Value <- predict(poly_mod)
predicted_Value
Final <- cbind(YearsofExp=YearsExperience,Sal_Hike = Salary,Pred_sal_hike=predicted_Value)
View(Final)
rmse<-sqrt(mean((predicted_Value-sh)^2))
rmse
plot(poly_mod)
hist(residuals(poly_mod))
Salary_hike_Model <- lm(Salary ~ YearsExperience, data = Salary_hike)
summary(Salary_hike_Model)
plot(Salary_hike_Model)