MNLogit#
- class pymc_marketing.customer_choice.mnl_logit.MNLogit(choice_df, utility_equations, depvar, covariates, 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
pd.DataFrame
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
offormula
strings
A list of formulas specifying how to model the utility of each product alternative. The formulas should be in Wilkinson style notation and allow the target product to be specified as as a function of the alternative specific attributes and the individual specific attributes: target_product ~ target_attribute1 + target_attribute2 | individual_attribute
- depvar
str
The name of the dependent variable in the choice_df.
- covariates
list
ofstr
Covariate names (e.g., [‘X1’, ‘X2’]).
- model_config
dict
, optional Model configuration. If None, the default config is used.
- sampler_config
dict
, optional Sampler configuration. If None, the default config is used.
- choice_df
Notes
Example:#
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_equations
list:>>> utility_equations = [ ... "alt_1 ~ X1_alt1 + X2_alt1 | income", ... "alt_2 ~ X1_alt2 + X2_alt2 | income", ... "alt_3 ~ X1_alt3 + X2_alt3 | income", ... ]
Methods
MNLogit.__init__
(choice_df, ...[, ...])Initialize model configuration and sampler configuration for the model.
MNLogit.apply_intervention
(new_choice_df[, ...])Apply one of two types of intervention.
MNLogit.attrs_to_init_kwargs
(attrs)Convert the model configuration and sampler configuration from the attributes to keyword arguments.
MNLogit.build_from_idata
(idata)Build model from the InferenceData object.
MNLogit.build_model
(X, y, **kwargs)Do not use, required by parent class.
MNLogit.calculate_share_change
(idata, new_idata)Calculate difference in market share due to market intervention.
MNLogit.create_fit_data
(X, y)Create the fit_data group based on the input data.
Create the attributes for the InferenceData object.
MNLogit.fit
(extend_idata, kwargs)Fit Nested Logit Model.
MNLogit.graphviz
(**kwargs)Get the graphviz representation of the model.
MNLogit.load
(fname)Create a ModelBuilder instance from a file.
MNLogit.load_from_idata
(idata)Create a ModelBuilder instance from an InferenceData object.
MNLogit.make_model
(X, F, y)Build Model.
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.predict
([X, extend_idata])Use a model to predict on unseen data and return point prediction of all the samples.
MNLogit.predict_posterior
([X, extend_idata, ...])Generate posterior predictive samples on unseen data.
MNLogit.predict_proba
([X, extend_idata, ...])Alias for
predict_posterior
, for consistency with scikit-learn probabilistic estimators.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 Posterior Predictive Distribution.
Sample Prior Predictive Distribution.
MNLogit.save
(fname)Save the model's inference data to a file.
MNLogit.set_idata_attrs
([idata])Set attributes on an InferenceData object.
Attributes
X
default_model_config
Default model configuration.
default_sampler_config
Default sampler configuration.
fit_result
Get the posterior fit_result.
id
Generate a unique hash value for the model.
output_var
The output variable of the model.
posterior
posterior_predictive
predictions
prior
prior_predictive
version
y