लिनियर रिग्रेशन
हम मानेंगे कि fertility, महिला निरक्षरता दर का एक लीनियर फंक्शन है. अर्थात, \(f = a i + b\), जहाँ \(a\) ढलान (slope) है और \(b\) इंटरसेप्ट. इंटरसेप्ट को हम न्यूनतम fertility दर की तरह देख सकते हैं, जो संभवतः 1 और 2 के बीच होगी. ढलान हमें बताती है कि निरक्षरता के साथ fertility दर कैसे बदलती है. हम np.polyfit() से best fit लाइन निकाल सकते हैं.
डेटा और best fit लाइन को प्लॉट करें. ढलान और इंटरसेप्ट को प्रिंट करें. (सोचिए: इनके यूनिट्स क्या होंगे?)
यह अभ्यास पाठ्यक्रम का हिस्सा है
Statistical Thinking in Python (Part 2)
अभ्यास निर्देश
np.polyfit()का उपयोग करके रिग्रेशन लाइन की ढलान और इंटरसेप्ट निकालें. ध्यान दें,fertilityy-axis पर है औरilliteracyx-axis पर.- लिनियर रिग्रेशन से प्राप्त ढलान और इंटरसेप्ट को प्रिंट करें.
- best fit लाइन प्लॉट करने के लिए
np.array()से 0 और 100 वाले मानों का arrayxबनाएँ. फिर अपने रिग्रेशन पैरामीटर्स के आधार पर सैद्धांतिकyनिकालें, यानीy = a * x + b. - उसी प्लॉट पर डेटा और रिग्रेशन लाइन दोनों प्लॉट करें. अपने axes को ज़रूर लेबल करें.
- अपना प्लॉट दिखाने के लिए सबमिट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Plot the illiteracy rate versus fertility
_ = plt.plot(illiteracy, fertility, marker='.', linestyle='none')
plt.margins(0.02)
_ = plt.xlabel('percent illiterate')
_ = plt.ylabel('fertility')
# Perform a linear regression using np.polyfit(): a, b
a, b = ____
# Print the results to the screen
print('slope =', a, 'children per woman / percent illiterate')
print('intercept =', b, 'children per woman')
# Make theoretical line to plot
x = ____
y = ____ * ____ + ____
# Add regression line to your plot
_ = plt.plot(____, ____)
# Draw the plot
plt.show()