choice.MultinomialLogit

Guide & worked example · Source

choice.MultinomialLogit(optimizer=None, maxiter=5000, tol=0.0001, device=None)

Multinomial Logit (MNL) model for discrete choice with multiple alternatives.

This model generalizes binary logit to J > 2 alternatives using the softmax (multinomial logit) link function. One alternative’s parameters are normalized to zero for identification.

Examples: >>> model = MultinomialLogit() >>> X = torch.randn(100, 3) >>> y = torch.zeros(100, 4) # 4 alternatives >>> y[range(100), torch.randint(0, 4, (100,))] = 1 # One-hot encode >>> model.fit(X, y) >>> probs = model.predict_proba(X)

Attributes

Name Description
device
history
maxiter
optimizer_class
params
tol

Methods

Name Description
counterfactual Compute change in market shares across alternatives for counterfactual.
fit Fit multinomial logit model with proper param initialization.
predict_proba Predict choice probabilities for each alternative.
simulate Simulate choices from the fitted multinomial logit model.
summary Print a formatted summary of model estimation results.
to Move model parameters and fitted data to device.

counterfactual

choice.MultinomialLogit.counterfactual(X_new)

Compute change in market shares across alternatives for counterfactual.

Args: X_new: Counterfactual design matrix of shape (n_samples, n_features).

Returns: Dictionary containing: - market_share_original: Market shares per alternative (n_choices,). - market_share_counterfactual: Counterfactual market shares. - change_in_market_share: Difference in market shares.

Raises: ValueError: If model has not been fitted yet.

fit

choice.MultinomialLogit.fit(X, y, init_params=None, verbose=False)

Fit multinomial logit model with proper param initialization.

Args: X: Design matrix of shape (n_samples, n_features). y: One-hot encoded choices of shape (n_samples, n_choices). init_params: Initial parameter matrix of shape (n_features, n_choices - 1). verbose: If True, prints convergence information.

Returns: Fitted model.

predict_proba

choice.MultinomialLogit.predict_proba(X)

Predict choice probabilities for each alternative.

Args: X: Design matrix of shape (n_samples, n_features).

Returns: Predicted probabilities of shape (n_samples, n_choices).

Raises: ValueError: If model has not been fitted yet.

simulate

choice.MultinomialLogit.simulate(X)

Simulate choices from the fitted multinomial logit model.

Args: X: Design matrix of shape (n_samples, n_features).

Returns: Simulated choice indices of shape (n_samples,).

summary

choice.MultinomialLogit.summary(alpha=0.05)

Print a formatted summary of model estimation results.

Displays a comprehensive table including parameter estimates, standard errors, t-statistics, p-values, and confidence intervals (if standard errors are available).

Args: alpha: Significance level for confidence intervals (default: 0.05 for 95% confidence intervals).

Examples: >>> model.fit(X, y) >>> model.summary(alpha=0.01) # 99% confidence intervals

to

choice.MultinomialLogit.to(device)

Move model parameters and fitted data to device.