線形回帰の結果を表示する
これまでの演習で作成した散布図に、線形回帰の結果を重ねて表示します。これを行うために、最初の 100 個のブートストラップ標本(bs_slope_reps_1975、bs_intercept_reps_1975、bs_slope_reps_2012、bs_intercept_reps_2012 に保存)を用い、plt.plot() に alpha=0.2 と linewidth=0.5 のキーワード引数を指定して線を描画してください。
この演習はコースの一部です
Pythonで学ぶ統計思考(パート2)
演習の手順
- ブートストラップ線用の x 値を
np.array()で生成します。10 mm と 17 mm の 2 点にしてください。 - 1975 年と 2012 年の各データセットについて、100 本のブートストラップ線を描く
forループを書きます。1975 年の線は'blue'、2012 年の線は'red'にします。 - "Submit Answer" を押してプロットを確認しましょう!
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Make scatter plot of 1975 data
_ = plt.plot(bl_1975, bd_1975, marker='.',
linestyle='none', color='blue', alpha=0.5)
# Make scatter plot of 2012 data
_ = plt.plot(bl_2012, bd_2012, marker='.',
linestyle='none', color='red', alpha=0.5)
# Label axes and make legend
_ = plt.xlabel('beak length (mm)')
_ = plt.ylabel('beak depth (mm)')
_ = plt.legend(('1975', '2012'), loc='upper left')
# Generate x-values for bootstrap lines: x
x = np.array([____, ____])
# Plot the bootstrap lines
for i in range(100):
plt.plot(____, ____,
linewidth=0.5, alpha=0.2, color=____)
plt.plot(____, ____,
linewidth=0.5, alpha=0.2, color=____)
# Draw the plot again
plt.show()