Dynamic Pricing with Contextual Bandits: Learning by Doing

Massimiliano Costacurta5 Oct 2023

Problem

A seller wants a price per customer segment, but the demand curve of each segment is unknown and differs by context. One global price leaves revenue on the table in price-insensitive segments and loses buyers in sensitive ones. Fixed-price A/B tests per segment are slow and sell at a bad price to part of the traffic.

The post simulates a shop with 8 contexts (2 regions, 4 age buckets) and a ladder of candidate prices, and looks for the best price per context while selling.

Example from the article: in the simulation the optimal price runs from 20 to 55 across contexts.

Solution in brief

Treat each candidate price as an arm of a contextual bandit with its own purchase-probability model. For a customer, predict the purchase probability at every price, multiply by the price, and offer the highest expected revenue. In 10% of cases offer another price (epsilon-greedy) to keep learning. In the simulation, a decision tree with epsilon-greedy had the lowest regret.

Questions this case answers
  • How to learn a per-segment optimal action online from binary feedback when the response curve differs by segment and every action receives only a fraction of the traffic
  • How to choose a price for each customer segment when demand curves differ by region and age and are unknown in advance?
  • How to learn the best price online without a long fixed-price A/B test per segment?
  • How to pick the model behind a contextual bandit when each price gets only a fraction of the data?

Tools and methods

  • Contextual multi-armed bandit — chooses a price per customer from the context and past outcomes
  • Greedy and epsilon-greedy policies — pick the best expected revenue, with or without exploring
  • Decision tree and logistic regression — per-price classifiers of purchase probability
  • Monte Carlo simulation — compares policies by regret over 1,000 runs
  • scikit-learn — DecisionTreeClassifier, SGDClassifier with log loss
Continue reading — it's free

Google or a one-time email code. No password.