自然界における相関データ
配列 grains には、穀粒サンプルの幅と長さが入っています。幅と長さには相関があると疑っています。これを確かめるために、幅と長さの散布図を作成し、ピアソン相関を測定してください。
この演習はコースの一部です
Pythonで学ぶ教師なし学習
演習の手順
- 次をインポートします:
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)