choice.LowRankLogit

Guide & worked example · Source

choice.LowRankLogit(
    rank,
    n_users,
    n_items,
    lam=0.0,
    optimizer=torch.optim.LBFGS,
    maxiter=20000,
    tol=0.0001,
    device=None,
)

Low-Rank Logit model for matrix completion style choice problems.

This model handles varying choice sets (assortments) by learning a low-rank factorization Θ = AB^T of the user-item utility matrix, where users choose from presented assortments according to multinomial logit probabilities.

Based on: Kallus & Udell (2016), “Revealed Preference at Scale: Learning Personalized Preferences from Assortment Choices”

Attributes

Name Description
device
history
lam
maxiter
n_items
n_users
optimizer_class
params
rank
tol

Methods

Name Description
counterfactual Perform counterfactual analysis comparing two assortment scenarios.
fit Fit the low-rank logit model.
predict_proba Predict choice probabilities.
simulate Simulate choices from the fitted model.
summary Print a formatted summary of model estimation results.
to Move model parameters and fitted data to device.

counterfactual

choice.LowRankLogit.counterfactual(
    user_indices,
    baseline_assortments,
    counterfactual_assortments,
    item_revenues=None,
)

Perform counterfactual analysis comparing two assortment scenarios.

This method evaluates the impact of changing the choice set (assortment) on market shares, choice probabilities, and optionally expected revenues. The low-rank structure allows heterogeneous user preferences, avoiding the IIA problem of standard multinomial logit.

Args: user_indices: User indices to evaluate (n_obs,) baseline_assortments: Binary mask (n_obs, n_items) for baseline scenario counterfactual_assortments: Binary mask (n_obs, n_items) for counterfactual item_revenues: Optional revenue per item (n_items,). If provided, computes expected revenues under each scenario.

Returns: dict containing: - baseline_probs: Choice probabilities under baseline (n_obs, n_items) - counterfactual_probs: Choice probabilities under counterfactual - baseline_market_share: Average choice probability per item (n_items,) - counterfactual_market_share: Average choice probability per item - market_share_change: Change in market share (n_items,) - baseline_expected_revenue: Expected revenue under baseline (if revenues provided) - counterfactual_expected_revenue: Expected revenue under counterfactual - revenue_change: Change in expected revenue - baseline_choices: Most likely choice per user under baseline (n_obs,) - counterfactual_choices: Most likely choice per user under counterfactual

Example: >>> # Evaluate impact of adding a new product (item 5) to assortments >>> baseline = torch.ones(n_obs, n_items) >>> baseline[:, 5] = 0 # Product 5 not available in baseline >>> counterfactual = torch.ones(n_obs, n_items) # All products available >>> results = model.counterfactual(users, baseline, counterfactual) >>> print(f”Adding product 5 changes market share by {results[‘market_share_change’][5]:.2%}“)

fit

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

Fit the low-rank logit model.

Args: X: User indices (n_obs,) y: Chosen item indices (n_obs,) assortments: Binary mask (n_obs, n_items) where 1 indicates item was available. If None, assumes all items are always available. init_params: Initial parameter values (optional) verbose: Print convergence information

Returns: self

predict_proba

choice.LowRankLogit.predict_proba(X, assortments=None)

Predict choice probabilities.

Args: X: User indices (n_obs,) assortments: Binary mask (n_obs, n_items) indicating available items. If None, assumes all items are available.

Returns: Choice probabilities (n_obs, n_items)

simulate

choice.LowRankLogit.simulate(X, assortments=None)

Simulate choices from the fitted model.

Args: X: User indices (n_obs,) assortments: Binary mask (n_obs, n_items) indicating available items. If None, assumes all items are available.

Returns: Simulated item choices (n_obs,)

summary

choice.LowRankLogit.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.LowRankLogit.to(device)

Move model parameters and fitted data to device.