可视化回归系数
既然您已经拟合了模型,接下来可视化其系数。这是机器学习中的重要步骤,因为它能帮助您理解模型中不同特征如何影响预测结果。
已在工作区中提供移位后的时间序列 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