More python3 warnings

This commit is contained in:
Raúl Marín 2019-12-19 17:17:53 +01:00
parent fb0b9d51b1
commit f5afd7c43f

View File

@ -156,7 +156,7 @@ class GWR(GLM):
self.kernel = kernel self.kernel = kernel
self.fixed = fixed self.fixed = fixed
if offset is None: if offset is None:
self.offset = np.ones((self.n, 1)) self.offset = np.ones((self.n, 1))
else: else:
self.offset = offset * 1.0 self.offset = offset * 1.0
self.fit_params = {} self.fit_params = {}
@ -169,7 +169,7 @@ class GWR(GLM):
def _build_W(self, fixed, kernel, coords, bw, points=None): def _build_W(self, fixed, kernel, coords, bw, points=None):
if fixed: if fixed:
try: try:
W = fk[kernel](coords, bw, points) W = fk[kernel](coords, bw, points)
except: except:
raise TypeError('Unsupported kernel function ', kernel) raise TypeError('Unsupported kernel function ', kernel)
else: else:
@ -496,7 +496,7 @@ class GWRResults(GLMResults):
""" """
if exog_scale is not None: if exog_scale is not None:
return cov*exog_scale return cov*exog_scale
else: else:
return cov*self.scale return cov*self.scale
@ -520,7 +520,7 @@ class GWRResults(GLMResults):
weighted mean of y weighted mean of y
""" """
if self.model.points is not None: if self.model.points is not None:
n = len(self.model.points) n = len(self.model.points)
else: else:
n = self.n n = self.n
off = self.offset.reshape((-1,1)) off = self.offset.reshape((-1,1))
@ -543,13 +543,13 @@ class GWRResults(GLMResults):
""" """
if self.model.points is not None: if self.model.points is not None:
n = len(self.model.points) n = len(self.model.points)
else: else:
n = self.n n = self.n
TSS = np.zeros(shape=(n,1)) TSS = np.zeros(shape=(n,1))
for i in range(n): for i in range(n):
TSS[i] = np.sum(np.reshape(np.array(self.W[i]), (-1,1)) * TSS[i] = np.sum(np.reshape(np.array(self.W[i]), (-1,1)) *
(self.y.reshape((-1,1)) - self.y_bar[i])**2) (self.y.reshape((-1,1)) - self.y_bar[i])**2)
return TSS return TSS
@cache_readonly @cache_readonly
@ -563,15 +563,15 @@ class GWRResults(GLMResults):
relationships. relationships.
""" """
if self.model.points is not None: if self.model.points is not None:
n = len(self.model.points) n = len(self.model.points)
resid = self.model.exog_resid.reshape((-1,1)) resid = self.model.exog_resid.reshape((-1,1))
else: else:
n = self.n n = self.n
resid = self.resid_response.reshape((-1,1)) resid = self.resid_response.reshape((-1,1))
RSS = np.zeros(shape=(n,1)) RSS = np.zeros(shape=(n,1))
for i in range(n): for i in range(n):
RSS[i] = np.sum(np.reshape(np.array(self.W[i]), (-1,1)) RSS[i] = np.sum(np.reshape(np.array(self.W[i]), (-1,1))
* resid**2) * resid**2)
return RSS return RSS
@cache_readonly @cache_readonly
@ -617,10 +617,10 @@ class GWRResults(GLMResults):
""" """
if isinstance(self.family, (Poisson, Binomial)): if isinstance(self.family, (Poisson, Binomial)):
return self.resid_ss/(self.n - 2.0*self.tr_S + return self.resid_ss/(self.n - 2.0*self.tr_S +
self.tr_STS) #could be changed to SWSTW - nothing to test against self.tr_STS) #could be changed to SWSTW - nothing to test against
else: else:
return self.resid_ss/(self.n - 2.0*self.tr_S + return self.resid_ss/(self.n - 2.0*self.tr_S +
self.tr_STS) #could be changed to SWSTW - nothing to test against self.tr_STS) #could be changed to SWSTW - nothing to test against
@cache_readonly @cache_readonly
def sigma2_ML(self): def sigma2_ML(self):
""" """
@ -680,7 +680,7 @@ class GWRResults(GLMResults):
y = self.y y = self.y
ybar = self.y_bar ybar = self.y_bar
if isinstance(self.family, Gaussian): if isinstance(self.family, Gaussian):
raise NotImplementedError('deviance not currently used for Gaussian') raise NotImplementedError('deviance not currently used for Gaussian')
elif isinstance(self.family, Poisson): elif isinstance(self.family, Poisson):
dev = np.sum(2.0*self.W*(y*np.log(y/(ybar*off))-(y-ybar*off)),axis=1) dev = np.sum(2.0*self.W*(y*np.log(y/(ybar*off))-(y-ybar*off)),axis=1)
elif isinstance(self.family, Binomial): elif isinstance(self.family, Binomial):
@ -690,7 +690,7 @@ class GWRResults(GLMResults):
@cache_readonly @cache_readonly
def resid_deviance(self): def resid_deviance(self):
if isinstance(self.family, Gaussian): if isinstance(self.family, Gaussian):
raise NotImplementedError('deviance not currently used for Gaussian') raise NotImplementedError('deviance not currently used for Gaussian')
else: else:
off = self.offset.reshape((-1,1)).T off = self.offset.reshape((-1,1)).T
y = self.y y = self.y
@ -708,7 +708,7 @@ class GWRResults(GLMResults):
manual. Equivalent to 1 - (deviance/null deviance) manual. Equivalent to 1 - (deviance/null deviance)
""" """
if isinstance(self.family, Gaussian): if isinstance(self.family, Gaussian):
raise NotImplementedError('Not implemented for Gaussian') raise NotImplementedError('Not implemented for Gaussian')
else: else:
return 1.0 - (self.resid_deviance/self.deviance) return 1.0 - (self.resid_deviance/self.deviance)
@ -831,8 +831,8 @@ class GWRResults(GLMResults):
def predictions(self): def predictions(self):
P = self.model.P P = self.model.P
if P is None: if P is None:
raise NotImplementedError('predictions only avaialble if predict' raise NotImplementedError('predictions only avaialble if predict'
'method called on GWR model') 'method called on GWR model')
else: else:
predictions = np.sum(P*self.params, axis=1).reshape((-1,1)) predictions = np.sum(P*self.params, axis=1).reshape((-1,1))
return predictions return predictions
@ -985,7 +985,7 @@ class FBGWR(GWR):
self.fixed = fixed self.fixed = fixed
self.constant = constant self.constant = constant
if constant: if constant:
self.X = USER.check_constant(self.X) self.X = USER.check_constant(self.X)
def fit(self, ini_params=None, tol=1.0e-5, max_iter=20, solve='iwls'): def fit(self, ini_params=None, tol=1.0e-5, max_iter=20, solve='iwls'):
""" """