- class Predictor(property_name: Optional[str] = None, external: bool = False, conditions_are_mutually_exclusive: Optional[bool] = None, conditions_are_exhaustive: Optional[bool] = False)¶
- class LinearModelType(value)¶
The type of model specifies how the results from the predictor are combined: ‘additive’ -> adds the effect_sizes from the predictors ‘logisitic’ -> multiples the effect_sizes from the predictors and applies the transform x/(1+x) [Thus, the intercept can be taken to be an Odds and effect_sizes Odds Ratios, and the prediction is a probability.] ‘multiplicative’ -> multiplies the effect_sizes from the predictors
- ADDITIVE = 1¶
- LOGISTIC = 2¶
- MULTIPLICATIVE = 3¶
- CUSTOM = 4¶
- class LinearModel(lm_type: LinearModelType, intercept: Union[float, int], *predictors: Predictor)¶
- property intercept: Union[float, int]¶
The intercept value for the model.
- static multiplicative(*predictors: Predictor)¶
Returns a multplicative LinearModel with intercept=1.0
predictors – One or more Predictor objects defining the model
- static custom(predict_function, **kwargs)¶
Define a linear model using the supplied function
The function acts as a drop-in replacement to the predict function and must implement the interface:
self: LinearModel, df: Union[pd.DataFrame, pd.Series], rng: Optional[np.random.RandomState] = None, **kwargs
) -> pd.Series
It is the responsibility of the caller of predict to ensure they pass either a dataframe or an individual record as expected by the custom function.
See test_custom() in test_lm.py for a couple of examples.
- predict(df: DataFrame, rng: Optional[RandomState] = None, squeeze_single_row_output=True, **kwargs) Series ¶
Evaluate linear model output for a given set of input data.
df – The input
DataFramecontaining the input data to evaluate the model with.
rng – If set to a NumPy
RandomStateinstance, returned output will be boolean
Seriescorresponding to Bernoulli random variables sampled according to probabilities specified by model output. Otherwise model output directly returned.
squeeze_single_row_output – If
rngargument is not
Noneand this argument is set to
True, the output for a
dfinput with a single-row will be a scalar boolean value rather than a boolean
Values for any external variables included in model predictors.