Refactor extraction of raw terms from regression result

This commit is contained in:
RunasSudo 2023-04-21 18:10:19 +10:00
parent f9a8a5cf01
commit fd30a3c1c7
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -455,6 +455,18 @@ class RegressionModel:
return out
def terms_flat(self):
"""
Iterate over each :class:`SingleTerm` in *self.terms*, recursively stepping through :class:`CategoricalTerm`\ s
"""
for t in self.terms.values():
if isinstance(t, CategoricalTerm):
for t in t.categories.values():
yield t
else:
yield t
# --------------------
# Post hoc tests, etc.
@ -477,11 +489,7 @@ class RegressionModel:
# Get parameters required for AFBF
raw_params = {}
for t in self.terms.values():
if isinstance(t, CategoricalTerm):
for t in t.categories.values():
raw_params[t.raw_name.replace('[', '_').replace(']', '_')] = t.beta.point
else:
for t in self.terms_flat():
raw_params[t.raw_name.replace('[', '_').replace(']', '_')] = t.beta.point
# Compute BF matrix