Get startedGet started for free

Displaying the linear regression results

Now, you will display your linear regression results on the scatter plot, which is already pre-generated for you from your previous exercise. To do this, take the first 100 bootstrap samples (stored in bs_slope_reps_1975, bs_intercept_reps_1975, bs_slope_reps_2012, and bs_intercept_reps_2012) and plot the lines with alpha=0.2 and linewidth=0.5 keyword arguments to plt.plot().

This exercise is part of the course

Statistical Thinking in Python (Part 2)

View Course

Exercise instructions

  • Generate the \(x\)-values for the bootstrap lines. They should consist of 10 mm and 17 mm.
  • Write a for loop to plot 100 of the bootstrap lines for the 1975 and 2012 data sets. The lines for the 1975 data set should be blue and those for the 2012 data set should be red.
  • Hit 'Submit Answer` to view the plot!

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Generate x-values for bootstrap lines: x
x = np.array([____, ____])

# Plot the bootstrap lines
for i in range(100):
    plt.plot(____, ____,
             linewidth=0.5, alpha=0.2, color=____)
    plt.plot(____, ____,
             linewidth=0.5, alpha=0.2, color=____)

# Draw the plot again
plt.draw()
Edit and Run Code