How to Price with Machine Learning

Whether we sell goods or services, we all have to put price tags on them. To find optimal prices, we need to understand how customers respond to prices. One way to do that is using price-response functions. In this article, we will build the function with Machine Learning and use them to optimize pricing strategies in the following order.
- Pricing Basics : Explain the law of supply and demand, and different price-response functions
- Price-Response Function with Machine Learning : Build price-response functions with neural network models
- Pricing Optimization : Find the best price changes by applying optimizers to price-response functions
We will use an example dataset artificially created by this process that imitates typical e-commerce data.
1. Pricing Basics
We all know supply and demand matter in pricing. More demand than supply leads to higher price, and the other way around. We call it "the law of supply and demand". The following is an example to describe prices relative to demands. This is a very simple "price-response function".

The relationship for most goods is not like this straight line. In the function, the fact that the price increase from 20 to 40 and another increase from 60 to 80 have the same quantity decrease of 200 doesn't make sense because buyers are likely to differently respond to different prices.
Let's say the market price is 50 for the example goods above. Then, a seller pricing it for 45 can expect a lot of demand increase. What if the seller sold it for 30? Would a higher discount bring more demand? Probably only a little more because the price 45 is already cheaper than the market price, beating most other sellers. Conversely, if the seller raised the price to 55, demand would drop significantly. But selling it for 70 may not be too worse because buyers wouldn't care about the difference between the price 55 and 70. To them, both are equally above the market price.

So, this curvy line, or a logit price-response function, should better describe the law of supply and demand for most goods. The relationship between the price and demand can be generalized in the following formula.

We should pay attention to three parameters in the logit price-response function.
- Maximum Demand : The demand at the price zero
- Bias : The term that moves the line to the left or right
- Sensitivity : The curviness of the line that shows how quickly or slowly demand responds to price changes
The examples below describe how the parameters play their roles in the function.

In the left plot, the bias parameter moved the line to the left, reflecting a different market price. The middle plot has a very small value for the sensitivity parameter, looking more like the linear price-response function. The right plot has such a higher sensitivity that any price change between 0 and 40 affects the demand drastically.
2. Price-Response Function with Machine Learning
Then, how do we formulate the price-response function? As a prerequisite, we need some ideas about the price elasticity for our goods which can be measured with experiments. For example, we can show different prices to randomized groups of customers for the same product. This way, we will see different conversion rates between the groups where the rate increases as the price decreases. With the pointwise price elasticity data (discrete), we are ready to customize a neural network model to fit the price-response function (continuous) using PyTorch like below.
To train the model, we will use this synthetic e-commerce data. The dataset consists of features such as goods, types like food or clothing, brand tiers like cheap or expensive, membership flag, and so on. Whether customers purchased the item or not is the target variable. The dataset would look like below, including the model outputs.
The model predicts the probability of being ordered between 0.0 and 1.0 for individual items where a price increase (decrease) must decrease (increase) the order probability (also called "win rate"). Together with this probability (predicted_order_prob
), the model is designed to output the three parameters (max_win_rate_param
, bias_param
, sensitivity_param
).
3. Pricing Optimization
Since we now have the price-response function fitted with the data, we want to answer our ultimate question; What changes should we make to our pricing? Let's analyze the predicted values and find the best price changes for our e-commerce business. The below are the price-response functions formed with the parameters averaged by brand tiers.

Let's assume our goal here is maximizing the revenue which can be estimated by multiplying the price and corresponding win rate. If lowering prices can increase win rates significantly (sensitive to price discount), then doing so should make sense. Conversely, if raising prices wouldn't decrease win rates too much (insensitive to price raise), that may also be okay to do. With that in mind, we can see our pricing for cheap brands is already close to the optimal price to maximize the revenue, but the other two may need some discounts because their win rates are likely to increase a lot.
Instead of making price changes only for brand tiers, what if we want to consider other aspects comprehensively? Indeed, we can iterate all the possible price changes for all the features to find the best set of adjustments that maximize the expected revenue. A better way is using a tool like Bayesian Optimizer like below.
The above adjusts prices for each item by any rate between -30% and +30% depending on the categorical features. Starting with a set of random adjustments, each iteration is evaluated by the sum of the expected revenue. As it continues, the optimizer tries another set of adjustments that should help us move closer to the maximum expected revenue. As a result, we may need the following pricing changes.
membership : +28.1%
tier cheap : -8.3%
tier highend : -5.6%
tier popular : +29.3%
goods type clothing : -27.9%
goods type electronics : +29.8%
goods type food : +23.4%
goods type furniture : +17.7%
goods type kichenware : +9.2%
goods type medicine : +26.9%
This article demonstrated how to formulate price-response functions with machine learning and optimize prices using them. The caveat is that every business has its own traits that may require this approach to be more or less modified or need a different approach entirely. If anyone wants to try, this notebook and the following references can help start.
- This article about price-response function in plain English
- This book price and revenue optimization (chapter 3)