Predicting from the unemployment model
In this exercise, you will use your unemployment model unemployment_model to make predictions from the unemployment data, and compare predicted female unemployment rates to the actual observed female unemployment rates on the training data, unemployment. You will also use your model to predict on the new data in newrates, which consists of only one observation, where male unemployment is 5%.
The predict() (docs) interface for lm models takes the form
predict(model, newdata)
You will use the ggplot2 package to make the plots, so you will add the prediction column to the unemployment data frame. You will plot outcome versus prediction, and compare them to the line that represents perfect predictions (that is when the outcome is equal to the predicted value).
The ggplot2 command to plot a scatterplot of  dframe$outcome versus dframe$pred (pred on the x axis, outcome on the y axis), along with a blue line where outcome == pred is as follows:
ggplot(dframe, aes(x = pred, y = outcome)) + 
       geom_point() +  
       geom_abline(color = "blue")
unemployment, unemployment_model, and newrates have been pre-loaded for you.
Este exercício faz parte do curso
Supervised Learning in R: Regression
Instruções do exercício
- Use predict()to predict female unemployment rates from theunemploymentdata. Assign it to a new column:prediction.
- Use the library()command to load theggplot2package.
- Use ggplot()to compare the predictions to actual unemployment rates. Put the predictions on the x axis. How close are the results to the line of perfect prediction?
- Use the data frame newratesto predict expected female unemployment rate when male unemployment is 5%. Assign the answer to the variablepredand print it.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# unemployment is available
summary(unemployment)
# newrates is available
newrates
# Predict female unemployment in the unemployment dataset
unemployment$prediction <-  ___
# Load the ggplot2 package
___
# Make a plot to compare predictions to actual (prediction on x axis). 
ggplot(___, aes(x = ___, y = ___)) + 
  ___ +
  geom_abline(color = "blue")
# Predict female unemployment rate when male unemployment is 5%
pred <- ___
pred