Visualizing a linear regression model
Now you have built your linear regression model and trained it using all available observations, you can visualize how well the model fits the data. This allows you to interpret the relationship between radio
advertising expenditure and sales
values.
The variables X
, an array of radio
values, y
, an array of sales
values, and predictions
, an array of the model's predicted values for y
given X
, have all been preloaded for you from the previous exercise.
This exercise is part of the course
Supervised Learning with scikit-learn
Exercise instructions
- Import
matplotlib.pyplot
asplt
. - Create a scatter plot visualizing
y
againstX
, with observations in blue. - Draw a red line plot displaying the predictions against
X
. - Display the plot.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import matplotlib.pyplot
import ____.____ as ____
# Create scatter plot
plt.scatter(____, ____, color="____")
# Create line plot
plt.plot(____, ____, color="____")
plt.xlabel("Radio Expenditure ($)")
plt.ylabel("Sales ($)")
# Display the plot
plt.____()