Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
# throw informative error message if any categorical predictors have 1
# category
num_cats = [x.data.size for x in self.fixed_terms.values()]
if any(np.array(num_cats) == 0):
raise ValueError("At least one categorical predictor contains only 1 category!")
# only set priors if there is at least one term in the model
if self.terms:
# Get and scale default priors if none are defined yet
if self.taylor is not None:
taylor = self.taylor
else:
taylor = 5 if self.family.name == "gaussian" else 1
scaler = PriorScaler(self, taylor=taylor)
scaler.scale()
# For bernoulli models with n_trials = 1 (most common use case),
# tell user which event is being modeled
if self.family.name == "bernoulli" and np.max(self.y.data) < 1.01:
event = next(i for i, x in enumerate(self.y.data.flatten()) if x > 0.99)
warnings.warn(
"Modeling the probability that {}=='{}'".format(
self.y.name, str(self.clean_data[self.y.name].iloc[event])
)
)
self._set_backend(backend)
self.backend.build(self)
self.built = True
["fixed"] * len(fixed_slopes)
+ ["intercept"] * len(fixed_intercepts)
+ ["random"] * len(random_terms)
)
# initialize them in order
for t, term_type in zip(term_list, term_types):
if t.prior.scale is None:
# pylint: disable=protected-access
if not t.prior._auto_scale or not self.model.auto_scale:
continue
t.prior.scale = "wide"
# Convert scale names to float
if isinstance(t.prior.scale, str):
t.prior.scale = PriorScaler.names[t.prior.scale]
# scale it!
getattr(self, "_scale_%s" % term_type)(t)