Linear regression के परिणाम प्रदर्शित करना
अब, आप अपने linear regression के परिणामों को scatter plot पर प्रदर्शित करेंगे, जिसका कोड आपके पिछले अभ्यास से पहले से प्री-लिखा हुआ है. ऐसा करने के लिए, पहले 100 bootstrap samples (जो bs_slope_reps_1975, bs_intercept_reps_1975, bs_slope_reps_2012, और bs_intercept_reps_2012 में संग्रहीत हैं) लें और plt.plot() में alpha=0.2 और linewidth=0.5 keyword arguments के साथ लाइनों को प्लॉट करें.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Statistical Thinking in Python (Part 2)
अभ्यास निर्देश
np.array()का उपयोग करके bootstrap लाइनों के लिए \(x\)-values जनरेट करें. इनमें 10 mm और 17 mm होने चाहिए.- 1975 और 2012 डेटासेट्स के लिए 100 bootstrap लाइनों को प्लॉट करने हेतु एक
forलूप लिखें. 1975 डेटासेट की लाइनों का रंग'blue'और 2012 डेटासेट की लाइनों का रंग'red'होना चाहिए. - प्लॉट देखने के लिए सबमिट करें!
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Make scatter plot of 1975 data
_ = plt.plot(bl_1975, bd_1975, marker='.',
linestyle='none', color='blue', alpha=0.5)
# Make scatter plot of 2012 data
_ = plt.plot(bl_2012, bd_2012, marker='.',
linestyle='none', color='red', alpha=0.5)
# Label axes and make legend
_ = plt.xlabel('beak length (mm)')
_ = plt.ylabel('beak depth (mm)')
_ = plt.legend(('1975', '2012'), loc='upper left')
# 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.show()