檢視迴歸用資料
下一個資料集包含多年間公司市值的資訊。這是迴歸最常見的時間序列資料之一。若能為公司隨時間變化的價值建立模型,就能預測該公司未來可能的位置。這個資料集最初也作為一個[公開 Kaggle 競賽](https://www.kaggle.com/dgawlik/nyse) 的一部分提供。
在本練習中,你會為多家公司的時間序列繪圖,來了解它們彼此之間是否相關,以及相關程度。
本練習屬於課程
Python 的時間序列資料機器學習
練習說明
- 使用 Pandas 匯入資料(檔名為
'prices.csv')。 - 將
data的索引轉換為datetime。 - 針對
data的每一個欄位進行迴圈,並將該欄位的數值隨時間繪圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Read in the data
data = pd.____('prices.csv', index_col=0)
# Convert the index of the DataFrame to datetime
data.index = ____(data.index)
print(data.head())
# Loop through each column, plot its values over time
fig, ax = plt.subplots()
for column in ____:
data[column].plot(ax=ax, label=column)
ax.legend()
plt.show()