You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Use the trained model to generate predictions for the testing sets
125
+
predict(lm.train,test) #The command gives a list of predicted value for each datapoint in the testing set
126
+
pred<- as.vector(predict(lm.train,test))
127
+
128
+
#Evaluate the performance of the model based on the predictions: calculating the MSE (mean squared error) of predictions
129
+
mse<-function(p, r)
130
+
{
131
+
mean((p-r)^2)
132
+
133
+
}
134
+
135
+
pmse.lm.train<-mse(pred,test$temp)
136
+
pmse.lm.train
137
+
138
+
#Practice question: how does pmse.lm.train compared to the MSE on the training set? Which value better represents the robustness of the model?
139
+
#Hint: use mean((lm.train$residuals)^2) to compute the MSE on training set
140
+
141
+
#####################
142
+
#
143
+
# Practice Problems
144
+
#
145
+
###################
146
+
#1. Develop a linear model to predict the rain, using all attributes (hint: you can write the formula this way: lm(rain~., data = fire) to indicate you are using all attributes)
147
+
148
+
#2. Look at the summary of the model. Which attributes are statistically significant? (with p-value < 0.05)
149
+
150
+
#3. Develop a linear model only using attributes that are statistically significant
151
+
152
+
#4. Compare model 1 and model 3. Are they statistically different? Which one would you choose?
153
+
154
+
#5. Split the dataset into trainning and testing set. Then use the training set to train the model you selected.
155
+
156
+
#6. Generate predictions for the testing sets.
157
+
158
+
#7. Compute the mean squared error of the predictions
0 commit comments