def plot_fit(self, **kwargs):
"""
Plots the fit of the model against the data
"""
import matplotlib.pyplot as plt
import seaborn as sns
figsize = kwargs.get('figsize',(10,7))
plt.figure(figsize=figsize)
date_index = self.index[max(self.ar, self.ma):self.data_length]
mu, Y = self._model(self.latent_variables.get_z_values())
# Catch specific family properties (imply different link functions/moments)
if self.model_name2 == "Exponential":
values_to_plot = 1.0/self.link(mu)
elif self.model_name2 == "Skewt":
t_params = self.transform_z()
model_scale, model_shape, model_skewness = self._get_scale_and_shape(t_params)
m1 = (np.sqrt(model_shape)*sp.gamma((model_shape-1.0)/2.0))/(np.sqrt(np.pi)*sp.gamma(model_shape/2.0))
additional_loc = (model_skewness - (1.0/model_skewness))*model_scale*m1
values_to_plot = mu + additional_loc
else:
values_to_plot = self.link(mu)
plt.plot(date_index, Y, label='Data')
plt.plot(date_index, values_to_plot, label='ARIMA model', c='black')
plt.title(self.data_name)
plt.legend(loc=2)
plt.show()
评论列表
文章目录