時間を追った予測
この演習では、NumPy 配列を使って、投資が20年間でどのように増えるかを調べます。予測は次の式で計算します。
\( balance = deposit (1 + rate)^{years} \)
20年間の各月における投資の増加率(パーセント)を計算してプロットします。時間を表す NumPy 配列 years は、deposit(元本)と annual_rate(年利)とともにワークスペースに読み込まれています。増加率の計算式は次のとおりです。
\( gain = \dfrac{(balance-deposit)}{deposit}\times100\)
この演習はコースの一部です
MATLABユーザーのためのPython
演習の手順
- 変数
yearsの各時点に対する口座残高を予測します。 - 口座の増加率(パーセント)を計算します。
- 年数に対する増加率をプロットします。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Calculate the balance in the account for each time in the variable years
balance =
# Calculate the percent gain in the account
percent_gain =
# Plot the percent gain as a function of years
plt.plot(____,____)
plt.____('Years')
plt.____('Percent Gain')
plt.____()