model_formula
- SimpleRegressor.model_formula(model)[source]
Creates the prediction formula of the fit for the encoded and normalized data. This function assumes the regressor was fitted with the result of
model2Y2X. In that case, the model can be provided to automatically generate the correct labels.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 did not create Y2X using
model2Y2X, useformula <pyoptex.analysis.mixins.fit_mixin.formula(). You must manually specify the labels here.Parameters
- modelpd.DataFrame
The dataframe of the model used in
model2Y2X.
Returns
- formulastr
The prediction formula for encoded and normalized data.