Don't show SciPy optimisation message in regression

This commit is contained in:
RunasSudo 2022-10-17 20:34:36 +11:00
parent 4340be165b
commit b24f675d57
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -396,13 +396,17 @@ def regress(
# Fit model
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):
# Already processed!
result.exp = exp
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
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_params = logit_result.raw_result.params
# Check convergence
if not logit_result.raw_result.mle_retvals['converged']:
return None
# Perform desired regression
return regress(model_class, df, dep, formula, start_params=logit_params, **kwargs)