Price optimization for e-commerce – case study

From this article, you will learn how we built an algorithm to select the optimal prices for the e-commerce company. Pricing is an essential part of e-commerce, here we’re presenting a case study about price optimization project for one of our clients.

Table of Contents

Price optimization is the process to determine how the client’s behavior will change when the price changes. There are a lot of articles describing how to set appropriate prices from economic, managemental, and sociological points of view. Here we are describing how we approached this task from the machine learning and statistics perspective.

Determining how customers will respond to different prices is a crucial part of any business. It helps to answer such questions as:

  • Which price is so high that your clients will be forced to go to your competitors?
  • Which price is so low that it will decrease the perceived value of your product?
  • How to find the optimum where your clients are satisfied, and the company makes money?
  • How often to change prices?
  • Did your price decrease noticeably?

All these questions can be addressed during the price optimization workflow and can be resolved all at once.

Main concepts

For one of our clients, we created a tailored algorithm specifically for their needs. The scope of the project was divided into three sections: building the algorithm, testing it in real-time and drawing the conclusions.

Building price optimization algorithm our ultimate goals were:

  1. Create an algorithm from scratch adjusted to the client’s needs
  2. Simple to maintain and develop in the future
  3. Fast to implement

We started from the extensive exploratory analysis to understand the patterns in data, discover inconsistencies to address in the early stages and to investigate presented trends.

During this stage, we found the weekly demand cycle for many products and changed prices once a week to see the effect of price change. We also identified products, that had almost no price changes; which was a critical point for us, because we had to use another approach to properly price them.

We worked with two main concepts: price elasticity and market basket penetration.

Price elasticity is the responsiveness of the quantity demanded of a good or service to a change in its price when nothing but the price changes.


%△in Qd – Percentage Change in Quantity

%△in P – Percentage Change in Price

Change in demand can be approached in two ways:

  1. As a change in the quantity of the product that someone buys, e.g., due to the decreased price same clients started to buy more units of the same product.
  2. As a change in market basket penetration for a product, e.g., old and new clients started to buy this product after the price changed. In this definition, a new client is someone who purchased other products from a particular category but not the product we are interested in.

When considering the first approach, some complications may arise.

Imagine that you usually buy 5L of water every two weeks. What will you do if one day you see that the price dropped by 50% on the water you buy? Probably, you will buy 20L and forget about this product for the next two months.

This kind of reasoning brought us to the realization that market basket penetration better suits our needs. Knowing the price elasticity of the products, we could change the price of more sensitive ones and expect an increase in sales, or increase the price of less sensitive and sell those products at the same sales rate.


We were eager to investigate the relationship between a price change and market basket penetration for each product, and for this purpose, we used the Bayesian approach.

Bayesian approach

Bayesian statistics interprets probability as a reasonable expectation based on prior knowledge. It has a few key benefits, comparing to the standard frequentist approach:

  • We get a distribution of likely estimations instead of only one “true” estimation, which informs us about the confidence our model has (wider distributions are less certain).
  • We can introduce expert knowledge to the model, e.g. by defining a proper distribution knowing that the price elasticity is mostly negative.
  • We can use a hierarchical Bayesian model, that allows us to do predictions for products with less empirical data, using general characteristics of the product category.

Going deeper into the advantages of the hierarchical Bayesian model, it is worth to mention its ability to combine several levels of one task. In our case, we wanted to estimate price elasticity and there were at least two possible levels: the product level and the category level. This allowed us to use the mean of the category in cases where we had a small data set of price changes for specific products. This phenomenon where the estimations for the product are influenced by the group is called shrinkage and it was a life-saver for the products with almost no price change history.

By the end of the first phase, we had the algorithm that was estimating how sensitive our products were and defining the appropriate price. During the testing phase of our project, we saw a significant increase in sales rate as well as margin in some categories caused by the decisions of our algorithm. It was a huge achievement for our team!

By the way, we did a talk on Data Science Summit about the Bayesian approach in e-commerce, covering hierarchical models as well as price-demand change analysis. If you what to dive into more tech details, follow this link.

Future development

This system can be used as a parameter in the reinforcement learning model when it weekly chooses the best prices based on all the different factors: weather, time of the year, sales rate before, price elasticity and product description. It can be a very efficient and effective tool in any e-commerce business.

Interested in doing such an analysis for your business? We are here to help!

Contact me to get answers to your questions:


Data Scientist

Data Scientist

Other stories in category

BlogKaggle Days
4 – Nature never goes out of style!

4 – Nature never goes out of style!

4 – Nature never goes out of ...

Five continents, twelve events, one grand finale, and a community of more than 10 million - that's Kaggle Days, a nonprofit event for data science enthusiasts and Kagglers. Beginning in November 2021, hundreds of participants attending each meetup face a daunting task to be on the podium and win one of three invitations to the finals in Barcelona and prizes from Kaggle Days and Z by HPZ by HP.

Paras Varshney

16 Aug 2022

BlogKaggle Days
3 – Now you are playing with power

3 – Now you are playing with power

3 – Now you are playing with ...

"It was amazing," commented attendees of the third Kaggle Days X Z by HP World Championship meetup, and we fully agree. The Moscow event brought together as many as 280 data science enthusiasts in one place to take on the challenge and compete for three spots in the grand finale of Kaggle Days in Barcelona. Of course, we already know the winning teams that best handled the contest task. In addition to the excitement of the competition, in Moscow were also inspiring lectures, speeches, and fascinating presentations of modern equipment. As always, at Kaggle Days, a lot was going on.

Paras Varshney

16 Aug 2022

BlogKaggle Days
2 – Water Water everywhere, not a drop to drink

2 – Water Water everywhere, not a drop to drink

2 – Water Water everywhere, n...

"Happy to be part of shaping the future." "It's the Way of The Future." That is how the participants summed up another meetup organized as part of Kaggle Days, a non-profit event for data science enthusiasts who want to grow and compete for prizes under the watchful eye of top Kaggle mentors and grandmasters. The second meetup in New Delhi is behind us. Three hundred participants, more than one hundred teams, and only three invitations to the finals in Barcelona mean that the excitement could not be lacking.

Paras Varshney

16 Aug 2022