MNLogit#
- class pymc_marketing.customer_choice.mnl_logit.MNLogit(choice_df=None, utility_equations=None, depvar=None, covariates=None, model_config=None, sampler_config=None)[source]#
Multinomial Logit class.
Class to perform a multinomial logit analysis with the specific intent of determining the product attribute effects on consumer preference.
- Parameters:
choice_df (
DataFrame|None) – Deprecated. Pass the choice data tofit()instead. A wide DataFrame where each row is a choice scenario. Product-specific attributes are stored in columns, and the dependent variable identifies the chosen product.utility_equations (
list[str] |None) –Formulas specifying how to model the utility of each product alternative. The formulas use Wilkinson style notation. The target product is specified as a function of the alternative-specific attributes. Individual-specific attributes may be added after a
|:target_product ~ target_attribute1 + target_attribute2 | individual_attribute
depvar (
str|None) – The name of the dependent variable in the choice_df.covariates (
list[str] |None) – Covariate names (e.g., [‘X1’, ‘X2’]).model_config (
dict|None) – Model configuration. If None, the default config is used.sampler_config (
dict|None) – Sampler configuration. If None, the default config is used.
Examples
The format of
choice_df:Depvar
alt_1_X1
alt_1_X2
alt_2_X1
alt_2_X2
alt_1
2.4
4.5
5.4
6.7
alt_2
3.5
6.7
2.3
8.9
Example
utility_equationslist:utility_equations = [ "alt_1 ~ X1_alt1 + X2_alt1 | income", "alt_2 ~ X1_alt2 + X2_alt2 | income", "alt_3 ~ X1_alt3 + X2_alt3 | income", ]
Create the model with its settings and pass the choice data to
fit:mnl = MNLogit( utility_equations=utility_equations, depvar="depvar", covariates=["X1", "X2"], ) mnl.fit(choice_df)
Methods
MNLogit.__init__([choice_df, ...])Initialize the model.
MNLogit.apply_intervention(new_choice_df[, ...])Apply one of two types of intervention.
MNLogit.attrs_to_init_kwargs(attrs)Rehydrate the
__init__kwargs from the serialised attrs.MNLogit.build_from_idata(idata)Build the model from a loaded DataTree.
MNLogit.build_model(**kwargs)Build the model from the stored choice data and utility equations.
MNLogit.calculate_share_change(idata, new_idata)Calculate difference in market share due to market intervention.
Build the
fit_datagroup storing the choice data.Create attributes for DataTree.
MNLogit.fit([choice_df, utility_equations, ...])Fit the discrete choice model.
MNLogit.graphviz(**kwargs)Get the graphviz representation of the model.
MNLogit.idata_to_init_kwargs(idata)Create the model configuration and sampler configuration from the DataTree to keyword arguments.
MNLogit.load(fname[, check])Create a ModelBuilder instance from a file.
MNLogit.load_from_idata(idata[, check])Create a ModelBuilder instance from a DataTree object.
Create coefficients for alternative-specific covariates.
Compute choice probabilities via softmax transformation.
MNLogit.make_fixed_coefs(X_fixed, n_obs, n_alts)Create alternative-varying coefficients for fixed (non-varying) covariates.
Create alternative-specific intercepts with reference alternative set to zero.
MNLogit.make_model(X, F, y, *[, coords])Build Model.
MNLogit.make_utility(X_data, alphas, betas, F)Compute systematic utility for each alternative.
MNLogit.parse_formula(df, formula, depvar)Parse the three-part structure of a formula specification.
MNLogit.plot_change(change_df[, title, figsize])Plot change induced by a market intervention.
Perform transformation on the model after sampling.
MNLogit.prepare_X_matrix(df, ...)Prepare the X matrix for the utility equations.
MNLogit.preprocess_model_data(choice_df, ...)Pre-process the model initiation inputs into a format that can be used by the PyMC model.
MNLogit.sample([...])Sample all the things.
Sample from posterior predictive distribution.
MNLogit.sample_prior_predictive([choice_df, ...])Sample from prior predictive distribution.
MNLogit.save(fname, **kwargs)Save the model's inference data to a file.
MNLogit.set_idata_attrs([idata])Set attributes on a DataTree object.
MNLogit.table(**model_table_kwargs)Get the summary table of the model.
Attributes
Default model configuration.
Default sampler configuration.
Get the posterior fit_result.
Generate a unique hash value for the model.
The output variable of the model.
Access the 'posterior' group of the DataTree.
Access the 'posterior_predictive' group of the DataTree.
Access the 'predictions' group of the DataTree.
Access the 'prior' group of the DataTree.
Access the 'prior_predictive' group of the DataTree.