Correlated data in nature
You are given an array grains giving the width and length of samples of grain. You suspect that width and length will be correlated. To confirm this, make a scatter plot of width vs length and measure their Pearson correlation.
Questo esercizio fa parte del corso
Unsupervised Learning in Python
Istruzioni dell'esercizio
- Import:
matplotlib.pyplotasplt.pearsonrfromscipy.stats.
- Assign column
0ofgrainstowidthand column1ofgrainstolength. - Make a scatter plot with
widthon the x-axis andlengthon the y-axis. - Use the
pearsonr()function to calculate the Pearson correlation ofwidthandlength.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# 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)