視覺化回歸係數
現在你已經擬合好模型,接下來把它的係數視覺化。這是機器學習中很重要的一步,因為它能幫你了解模型中的不同特徵如何影響結果。
已經在你的工作空間中提供了位移過的時間序列 DataFrame(prices_perc_shifted)以及回歸模型(model)。
在這個練習中,你會撰寫一個函式,給定一組係數與對應的特徵名稱,將係數值視覺化。
本練習屬於課程
Python 的時間序列資料機器學習
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
def visualize_coefficients(coefs, names, ax):
# Make a bar plot for the coefficients, including their names on the x-axis
ax.bar(____, ____)
ax.set(xlabel='Coefficient name', ylabel='Coefficient value')
# Set formatting so it looks nice
plt.setp(ax.get_xticklabels(), rotation=45, horizontalalignment='right')
return ax