pysal / spint

SPatial INTeraction Models (spint)
BSD 3-Clause "New" or "Revised" License
51 stars 22 forks source link

There are a lot of errors with the local function #33

Open vangjunxiu opened 2 years ago

vangjunxiu commented 2 years ago

model = Gravity(flows, Oi, Dj, Dij, 'exp') local= model.local(loc_index=Origin, locs=np.unique(Origin))

Exception Traceback (most recent call last) Input In [19], in 1 model = Gravity(flows, Oi, Dj, Dij, 'exp') ----> 2 local= model.local(loc_index=Origin, locs=np.unique(Origin))

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\spint\gravity.py:478, in Gravity.local(self, loc_index, locs) 476 d_vars = self.dv[subset.reshape(self.dv.shape[0]),:] 477 dij = self.reshape(self.c[subset]) --> 478 model = Gravity(f, o_vars, d_vars, dij, self.cf, 479 constant=False) 480 results['AIC'].append(model.AIC) 481 results['deviance'].append(model.deviance)

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\spint\gravity.py:429, in Gravity.init(self, flows, o_vars, d_vars, cost, cost_func, constant, framework, SF, CD, Lag, Quasi) 426 self.c = np.reshape(cost, (-1,1)) 427 #User.check_arrays(self.f, self.ov, self.dv, self.c) --> 429 BaseGravity.init(self, self.f, self.c, 430 cost_func=cost_func, o_vars=self.ov, d_vars=self.dv, constant=constant, 431 framework=framework, SF=SF, CD=CD, Lag=Lag, Quasi=Quasi)

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\spint\gravity.py:245, in BaseGravity.init(self, flows, cost, cost_func, o_vars, d_vars, origins, destinations, constant, framework, SF, CD, Lag, Quasi) 243 if (framework.lower() == 'glm'): 244 if not Quasi: --> 245 results = self.fit(framework='glm') 246 else: 247 results = self.fit(framework='glm', Quasi=True)

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\spint\count_model.py:87, in CountModel.fit(self, framework, Quasi) 85 if (framework.lower() == 'glm'): 86 if not Quasi: ---> 87 results = GLM(self.y, self.X, family = Poisson(), constant=self.constant).fit() 88 else: 89 results = GLM(self.y, self.X, family = QuasiPoisson(), constant=self.constant).fit()

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\glm\glm.py:81, in GLM.init(self, y, X, family, offset, y_fix, constant) 76 def init(self, y, X, family=family.Gaussian(), offset=None, y_fix = None, 77 constant=True): 78 """ 79 Initialize class 80 """ ---> 81 self.n = USER.check_arrays(y, X) 82 USER.check_y(y, self.n) 83 self.y = y

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\spreg\user_output.py:358, in check_arrays(*arrays) 356 raise Exception("all input arrays must have exactly two dimensions") 357 if shape[0] < shape[1]: --> 358 raise Exception("one or more input arrays have more columns than rows") 359 if not spu.spisfinite(i): 360 raise Exception("one or more input arrays have missing/NaN values")

Exception: one or more input arrays have more columns than rows


ZeroDivisionError Traceback (most recent call last) Input In [5], in 1 model = Gravity(flows, Oi, Dj, Dij, 'exp') ----> 2 local= model.local(loc_index=Origin, locs=np.unique(Origin))

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\spint\gravity.py:478, in Gravity.local(self, loc_index, locs) 476 d_vars = self.dv[subset.reshape(self.dv.shape[0]),:] 477 dij = self.reshape(self.c[subset]) --> 478 model = Gravity(f, o_vars, d_vars, dij, self.cf, 479 constant=False) 480 results['AIC'].append(model.AIC) 481 results['deviance'].append(model.deviance)

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\spint\gravity.py:429, in Gravity.init(self, flows, o_vars, d_vars, cost, cost_func, constant, framework, SF, CD, Lag, Quasi) 426 self.c = np.reshape(cost, (-1,1)) 427 #User.check_arrays(self.f, self.ov, self.dv, self.c) --> 429 BaseGravity.init(self, self.f, self.c, 430 cost_func=cost_func, o_vars=self.ov, d_vars=self.dv, constant=constant, 431 framework=framework, SF=SF, CD=CD, Lag=Lag, Quasi=Quasi)

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\spint\gravity.py:245, in BaseGravity.init(self, flows, cost, cost_func, o_vars, d_vars, origins, destinations, constant, framework, SF, CD, Lag, Quasi) 243 if (framework.lower() == 'glm'): 244 if not Quasi: --> 245 results = self.fit(framework='glm') 246 else: 247 results = self.fit(framework='glm', Quasi=True)

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\spint\count_model.py:90, in CountModel.fit(self, framework, Quasi) 88 else: 89 results = GLM(self.y, self.X, family = QuasiPoisson(), constant=self.constant).fit() ---> 90 return CountModelResults(results) 92 else: 93 raise NotImplemented('Poisson GLM is the only count model currently implemented')

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\spint\count_model.py:186, in CountModelResults.init(self, results) 184 self.tvalues = results.tvalues 185 self.D2 = results.D2 --> 186 self.adj_D2 = results.adj_D2 187 self.pseudoR2 = results.pseudoR2 188 self.adj_pseudoR2 = results.adj_pseudoR2

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\glm\utils.py:370, in CachedAttribute.get(self, obj, type) 367 # print("[_cachedval=%s]" % _cachedval) 368 if _cachedval is None: 369 # Call the "fget" function --> 370 _cachedval = self.fget(obj) 371 # Set the attribute in obj 372 # print("Setting %s in cache to %s" % (name, _cachedval)) 373 try:

File D:\Anaconda3\envs\tensorflow\lib\site-packages\pysal\contrib\glm\glm.py:370, in GLMResults.adj_D2(self) 368 @cache_readonly 369 def adj_D2(self): --> 370 return 1.0 - (float(self.n) - 1.0)/(float(self.n) - float(self.k)) * (1.0-self.D2)

ZeroDivisionError: float division by zero

ljwolf commented 2 years ago

Can you post your data? These errors seem to be related to the structure of your input data.

vangjunxiu commented 2 years ago

I can give you my data, hope you can point me to solve these problems, thank you.

vangjunxiu commented 2 years ago

I have sent the data to your mailbox,thank you.

ljwolf commented 2 years ago

I uploaded the data here. I will look into this as best I can in the coming week.

Workday_OD.csv