Modeling with categorical inputs
For this exercise, you will fit a linear model to the flowers
data, to predict Flowers
as a function of Time
and Intensity
.
The model formula fmla
that you created in the previous exercise is still available, as is the model matrix mmat
.
This exercise is part of the course
Supervised Learning in R: Regression
Exercise instructions
- Use
fmla
andlm
to train a linear model that predictsFlowers
fromIntensity
andTime
. Assign the model to the variableflower_model
. - Use
summary()
to remind yourself of the structure ofmmat
. - Use
summary()
to examine theflower_model
. Do the variables match what you saw inmmat
? - Use
flower_model
to predict the number of flowers. Add the predictions toflowers
as the columnpredictions
. - Fill in the blanks to plot predictions vs. actual flowers (predictions on the x-axis).
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# flowers is available
str(flowers)
# fmla is available
fmla
# Fit a model to predict Flowers from Intensity and Time : flower_model
flower_model <- ___
# Use summary on mmat to remind yourself of its structure
___
# Use summary to examine flower_model
___
# Predict the number of flowers on each plant
flowers$predictions <- ___
# Plot predictions vs actual flowers (predictions on x-axis)
ggplot(___, aes(x = ___, y = ___)) +
geom_point() +
geom_abline(color = "blue")