|
|
@ -49,7 +49,7 @@ def iwls(y, x, family, offset=1.0, ini_betas=None, tol=1.0e-8, max_iter=200, wi=
|
|
|
|
if isinstance(family, Binomial):
|
|
|
|
if isinstance(family, Binomial):
|
|
|
|
y = family.link._clean(y)
|
|
|
|
y = family.link._clean(y)
|
|
|
|
if isinstance(family, Poisson):
|
|
|
|
if isinstance(family, Poisson):
|
|
|
|
y_off = y/offset
|
|
|
|
y_off = y/offset
|
|
|
|
y_off = family.starting_mu(y_off)
|
|
|
|
y_off = family.starting_mu(y_off)
|
|
|
|
v = family.predict(y_off)
|
|
|
|
v = family.predict(y_off)
|
|
|
|
mu = family.starting_mu(y)
|
|
|
|
mu = family.starting_mu(y)
|
|
|
@ -58,13 +58,13 @@ def iwls(y, x, family, offset=1.0, ini_betas=None, tol=1.0e-8, max_iter=200, wi=
|
|
|
|
v = family.predict(mu)
|
|
|
|
v = family.predict(mu)
|
|
|
|
|
|
|
|
|
|
|
|
while diff > tol and n_iter < max_iter:
|
|
|
|
while diff > tol and n_iter < max_iter:
|
|
|
|
n_iter += 1
|
|
|
|
n_iter += 1
|
|
|
|
w = family.weights(mu)
|
|
|
|
w = family.weights(mu)
|
|
|
|
z = v + (family.link.deriv(mu)*(y-mu))
|
|
|
|
z = v + (family.link.deriv(mu)*(y-mu))
|
|
|
|
w = np.sqrt(w)
|
|
|
|
w = np.sqrt(w)
|
|
|
|
if type(x) != np.ndarray:
|
|
|
|
if type(x) != np.ndarray:
|
|
|
|
w = sp.csr_matrix(w)
|
|
|
|
w = sp.csr_matrix(w)
|
|
|
|
z = sp.csr_matrix(z)
|
|
|
|
z = sp.csr_matrix(z)
|
|
|
|
wx = spmultiply(x, w, array_out=False)
|
|
|
|
wx = spmultiply(x, w, array_out=False)
|
|
|
|
wz = spmultiply(z, w, array_out=False)
|
|
|
|
wz = spmultiply(z, w, array_out=False)
|
|
|
|
if wi is None:
|
|
|
|
if wi is None:
|
|
|
|