多個時間序列之間的相關性
在上一個練習中,你已經從 jobs DataFrame 的每個時間序列中抽取 seasonal 元件,並把結果存成新的 DataFrame,命名為 seasonality_df。在就業資料的情境下,比較季節性行為很有意思,因為這能幫助你找出哪些就業產業最相似或最不同。
你可以使用 seasonality_df DataFrame,計算資料集中各時間序列之間的相關性來達成這個目的。在本練習中,你會運用第 4 章所學,計算並建立 seasonality_df DataFrame 中各時間序列之間相關性的 clustermap 視覺化。
本練習屬於課程
使用 Python 視覺化時間序列資料
練習說明
- 使用 spearman 方法計算
seasonality_dfDataFrame 中所有欄位之間的相關性,並將結果指定給seasonality_corr。 - 以你的相關矩陣建立一個新的 clustermap。
- 列印 Government 與 Education & Health 兩個產業的季節性之間的相關係數值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Get correlation matrix of the seasonality_df DataFrame
seasonality_corr = ____
# Customize the clustermap of the seasonality_corr correlation matrix
fig = ____(____, annot=True, annot_kws={"size": 4}, linewidths=.4, figsize=(15, 10))
plt.setp(fig.ax_heatmap.yaxis.get_majorticklabels(), rotation=0)
plt.setp(fig.ax_heatmap.xaxis.get_majorticklabels(), rotation=90)
plt.show()
# Print the correlation between the seasonalities of the Government and Education & Health industries
print(____)