自然界に見られる相関データ
配列grainsには、穀物サンプルの幅と長さが入っています。幅と長さには相関があると考えられます。これを確認するために、幅と長さの散布図を作成し、ピアソン相関係数を計算しましょう。
この演習はコースの一部です
Pythonで学ぶ教師なし学習
演習の手順
- 以下をインポートしてください。
- 別名
pltをつけたmatplotlib.pyplot scipy.statsからpearsonr
- 別名
grainsの0列をwidthに、grainsの1列をlengthに割り当ててください。widthをx軸、lengthをy軸にした散布図を作成してください。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)