File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -264,14 +264,20 @@ def reg_func(_x, _y):
264264
265265 def fit_statsmodels (self , grid , model , ** kwargs ):
266266 """More general regression function using statsmodels objects."""
267- import statsmodels .genmod . generalized_linear_model as glm
267+ import statsmodels .tools . sm_exceptions as sme
268268 X , y = np .c_ [np .ones (len (self .x )), self .x ], self .y
269269 grid = np .c_ [np .ones (len (grid )), grid ]
270270
271271 def reg_func (_x , _y ):
272+ err_classes = (sme .PerfectSeparationError ,)
272273 try :
273- yhat = model (_y , _x , ** kwargs ).fit ().predict (grid )
274- except glm .PerfectSeparationError :
274+ with warnings .catch_warnings ():
275+ if hasattr (sme , "PerfectSeparationWarning" ):
276+ # statsmodels>=0.14.0
277+ warnings .simplefilter ("error" , sme .PerfectSeparationWarning )
278+ err_classes = (* err_classes , sme .PerfectSeparationWarning )
279+ yhat = model (_y , _x , ** kwargs ).fit ().predict (grid )
280+ except err_classes :
275281 yhat = np .empty (len (grid ))
276282 yhat .fill (np .nan )
277283 return yhat
You can’t perform that action at this time.
0 commit comments