Don't show SciPy optimisation message in regression
This commit is contained in:
parent
4340be165b
commit
b24f675d57
@ -396,13 +396,17 @@ def regress(
|
|||||||
|
|
||||||
# Fit model
|
# Fit model
|
||||||
model = model_class.from_formula(formula=dep + ' ~ ' + formula, data=df, **model_kwargs)
|
model = model_class.from_formula(formula=dep + ' ~ ' + formula, data=df, **model_kwargs)
|
||||||
result = model.fit(**fit_kwargs)
|
result = model.fit(disp=False, **fit_kwargs)
|
||||||
|
|
||||||
if isinstance(result, RegressionResult):
|
if isinstance(result, RegressionResult):
|
||||||
# Already processed!
|
# Already processed!
|
||||||
result.exp = exp
|
result.exp = exp
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
# Check convergence
|
||||||
|
if hasattr(result, 'mle_retvals') and not result.mle_retvals['converged']:
|
||||||
|
warnings.warn('Maximum likelihood estimation failed to converge. Check raw_result.mle_retvals.')
|
||||||
|
|
||||||
# Process terms
|
# Process terms
|
||||||
terms = {}
|
terms = {}
|
||||||
|
|
||||||
@ -478,6 +482,10 @@ def logit_then_regress(model_class, df, dep, formula, *, nan_policy='warn', **kw
|
|||||||
logit_result = regress(sm.Logit, df, dep, formula, **kwargs)
|
logit_result = regress(sm.Logit, df, dep, formula, **kwargs)
|
||||||
logit_params = logit_result.raw_result.params
|
logit_params = logit_result.raw_result.params
|
||||||
|
|
||||||
|
# Check convergence
|
||||||
|
if not logit_result.raw_result.mle_retvals['converged']:
|
||||||
|
return None
|
||||||
|
|
||||||
# Perform desired regression
|
# Perform desired regression
|
||||||
return regress(model_class, df, dep, formula, start_params=logit_params, **kwargs)
|
return regress(model_class, df, dep, formula, start_params=logit_params, **kwargs)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user