PCA के साथ अनाज मापों को डिकॉरिलेट करना
पिछले अभ्यास में आपने देखा कि अनाज की चौड़ाई और लंबाई के माप आपस में सह-संबद्ध हैं. अब, आप PCA का उपयोग करके इन मापों को डिकॉरिलेट करेंगे, फिर डिकॉरिलेट किए गए पॉइंट्स को प्लॉट करेंगे और उनका पीयरसन कोरिलेशन नापेंगे.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Unsupervised Learning
अभ्यास निर्देश
sklearn.decompositionसेPCAइम्पोर्ट करें.PCAका एक इंस्टेंस बनाएँ और उसेmodelनाम दें.modelकी.fit_transform()मेथड का उपयोग करकेgrainsपर PCA ट्रांसफॉर्मेशन लगाएँ. परिणाम कोpca_featuresमें असाइन करें.- इसके बाद वाला कोड
pca_featuresके पहले दो कॉलम्स को निकालने, प्लॉट करने, और उनका पीयरसन कोरिलेशन निकालने के लिए पहले से लिखा हुआ है, तो परिणाम देखने के लिए बस सबमिट करें!
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import PCA
____
# Create PCA instance: model
model = ____
# Apply the fit_transform method of model to grains: pca_features
pca_features = ____
# Assign 0th column of pca_features: xs
xs = pca_features[:,0]
# Assign 1st column of pca_features: ys
ys = pca_features[:,1]
# Scatter plot xs vs ys
plt.scatter(xs, ys)
plt.axis('equal')
plt.show()
# Calculate the Pearson correlation of xs and ys
correlation, pvalue = pearsonr(xs, ys)
# Display the correlation
print(correlation)