प्रकृति में सह-संबद्ध डेटा
आपको एक ऐरे grains दिया गया है, जिसमें अनाज के सैंपल्स की चौड़ाई (width) और लंबाई (length) है। आपको संदेह है कि चौड़ाई और लंबाई सह-संबद्ध होंगी। इसे जाँचने के लिए, width बनाम length का स्कैटर प्लॉट बनाएँ और उनका पियर्सन कोरिलेशन मापें.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Unsupervised Learning
अभ्यास निर्देश
- इम्पोर्ट करें:
matplotlib.pyplotकोpltनाम से.scipy.statsसेpearsonr.
grainsके कॉलम0कोwidthऔर कॉलम1कोlengthको असाइन करें.- x-अक्ष पर
widthऔर y-अक्ष परlengthके साथ एक स्कैटर प्लॉट बनाएँ. pearsonr()फंक्शन का उपयोग करकेwidthऔरlengthका पियर्सन कोरिलेशन कैलकुलेट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Perform the necessary imports
____
____
# Assign the 0th column of grains: width
width = ____
# Assign the 1st column of grains: length
length = ____
# Scatter plot width vs length
plt.scatter(____, ____)
plt.axis('equal')
plt.show()
# Calculate the Pearson correlation
correlation, pvalue = ____
# Display the correlation
print(correlation)