Ejemplo n.º 1
0
ythat = glm_poisson[-1].predict(scaler.transform(Xt))

plt.plot(yt[:100], label='true')
plt.plot(ythat[:100], 'r', label='predicted')
plt.xlabel('samples')
plt.ylabel('true and predicted outputs')
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102),
           loc=1,
           ncol=2,
           borderaxespad=0.)
plt.show()

##########################################################
# Goodness of fit
# ^^^^^^^^^^^^^^^
# The GLM class provides two metrics to evaluate the goodness of fit: ``deviance``
# and ``pseudo_R2``. Both these metrics are implemented in the ``score()`` method.

##########################################################

# Compute model deviance
Dr = glm_poisson[-1].score(Xr, yr)
Dt = glm_poisson[-1].score(Xt, yt)
print('Dr = %f' % Dr, 'Dt = %f' % Dt)

# Compute pseudo_R2s
glm_poisson.score_metric = 'pseudo_R2'
R2r = glm_poisson[-1].score(Xr, yr)
R2t = glm_poisson[-1].score(Xt, yt)
print('  R2r =  %f' % R2r, ' R2r = %f' % R2t)