'Fits a generalized linear model for a given family iteratively
using the scipy gradient optimizers.'

def _fit_gradient(self, start_params=None, method='newton', maxiter=100, tol=1e-08, full_output=True, disp=True, scale=None, cov_type='nonrobust', cov_kwds=None, use_t=None, max_start_irls=3, **kwargs):

    if ((max_start_irls > 0) and (start_params is None)):
        irls_rslt = self._fit_irls(start_params=start_params, maxiter=max_start_irls, tol=tol, scale=scale, cov_type=cov_type, cov_kwds=cov_kwds, use_t=use_t, **kwargs)
        start_params = irls_rslt.params
    rslt = super(GLM, self).fit(start_params=start_params, tol=tol, maxiter=maxiter, full_output=full_output, method=method, disp=disp, **kwargs)
    mu = self.predict(rslt.params)
    scale = self.estimate_scale(mu)
    if (rslt.normalized_cov_params is None):
        cov_p = None
    else:
        cov_p = (rslt.normalized_cov_params / scale)
    glm_results = GLMResults(self, rslt.params, cov_p, scale, cov_type=cov_type, cov_kwds=cov_kwds, use_t=use_t)
    history = {'iteration': 0}
    if full_output:
        glm_results.mle_retvals = rslt.mle_retvals
        if ('iterations' in rslt.mle_retvals):
            history['iteration'] = rslt.mle_retvals['iterations']
    glm_results.method = method
    glm_results.fit_history = history
    return GLMResultsWrapper(glm_results)
