formula
- ConditionalRegressionMixin.formula(labels=None)[source]
Creates the prediction formula of the fit for the encoded and normalized data. The labels for each term are given by the labels parameter. The number of labels must be the number of parameters from Y2X, i.e., len(labels) == Y2X(Y).shape[1].
It also includes the conditional effects automatically.
Warning
This formula is the prediction formula of the encoded and normalized data. First apply factor normalization and then categorical encoding before applying this prediction formula.
>>> # Imports >>> from numba.typed import List >>> from pyoptex.utils import Factor >>> from pyoptex.utils.design import encode_design >>> >>> # Example factors >>> factors = [ >>> Factor('A'), >>> Factor('B'), >>> Factor('C', type='categorical', levels=['L1', 'L2', 'L3']) >>> ] >>> >>> # Compute derived parameters >>> effect_types = np.array([ >>> 1 if f.is_continuous else len(f.levels) >>> for f in factors >>> ]) >>> coords = List([f.coords_ for f in factors]) >>> >>> # Normalize the factors >>> for f in factors: >>> data[str(f.name)] = f.normalize(data[str(f.name)]) >>> >>> # Select correct order + to numpy >>> data = data[[str(f.name) for f in factors]].to_numpy() >>> >>> # Encode >>> data = encode_design(data, effect_types, coords=coords) >>> >>> # Transform according to the model >>> data = Y2X(data)
Note
If you created Y2X using
model2Y2X, usemodel_formula <pyoptex.analysis.mixins.fit_mixin.model_formula(). It will automatically assign the correct labels.Parameters
- labelslist(str)
The list of labels for each encoded, normalized term.
Returns
- formulastr
The prediction formula for encoded and normalized data.