Minimizing the Residuals
In this exercise, you will complete a function to visually compare model and data, and compute and print the RSS. You will call it more than once to see how RSS changes when you change values for a0 and a1. We'll see that the values for the parameters we found earlier are the ones needed to minimize the RSS.
This exercise is part of the course
Introduction to Linear Modeling in Python
Exercise instructions
- Fill in the call to
model()passing in the dataxdand model parametersa0anda1. - Compute
rssas the sum of the square of theresiduals. - Use
compute_rss_and_plot_fit()for various values ofa0anda1to see how they change RSS. - Convince yourself that the original values
a0=150anda1=25minimize RSS, and submit your answer with these.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Complete function to load data, build model, compute RSS, and plot
def compute_rss_and_plot_fit(a0, a1):
xd, yd = load_data()
ym = model(xd, ____, ____)
residuals = ym - yd
rss = np.sum(np.square(____))
summary = "Parameters a0={}, a1={} yield RSS={:0.2f}".format(____, ____, rss)
fig = plot_data_with_model(xd, yd, ym, summary)
return rss, summary
# Chose model parameter values and pass them into RSS function
rss, summary = compute_rss_and_plot_fit(a0=____, a1=____)
print(summary)