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.
Latihan ini adalah bagian dari kursus
Supervised Learning with scikit-learn
Petunjuk latihan
- Import
matplotlib.pyplotasplt. - Create a scatter plot visualizing
yagainstX, with observations in blue. - Draw a red line plot displaying the predictions against
X. - Display the plot.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# 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.____()