How can we decide on a product or service price using observed data over time? For example, a retailer may have changed the price for a specific product in multiple time slots of a week, tested the demanded quantity (sales) based on different prices, and now wants to know the optimal price to set for the next week. Notably, the optimal price should maximize the total revenue of the retailer. This article describes how the optimal price can be determined using Gekko in Python. It can be one of the possible cases in which optimization and machine learning can be integrated!
Modeling and solving the pricing problem in Python
At first, I code the decision problem according to the following assumptions and the elements of the decision making environment:
- Consists of Quantity-Price observations over business days of the previous week.
The demand function:
- Is estimated via linear regression.
- Can be of any type, any kind, with any characteristic.
- Has had a specific amount of sales during the previous week.
- Has experienced different levels of prices during the previous week.
Consider a dataset as follows:
Herein, I provide a simple code that models the decision problem, satisfying the mentioned assumptions based on this dataset:
This code fits a linear function (we call it linear demand function) and finds a slope and intercept to minimize the prediction error. Accordingly, it results to the following output:
Next, we want to set an optimal price for our product/service with a predicted linear demand function at hand to maximize revenue. Considering that revenue is generated by the quantity of sales times the price set, the following optimization model should be solved to find the optimal price:
Solving the above model results to the following output:
Therefore, it is suggested to set the price at 16.26 $ to generate maximum revenue possible (i.e., 8873.67$)!
In this article, I described how a machine learning model can be integrated with an optimization model to set an optimal price for our product/service. The interested readers can learn more about applications of optimization in machine learning, or solvers and interfaces in Python by visiting the linked references. If you find these contents insightful, let us know by commenting below this article! You may also contact us at this link.
If this article is going to be used in research or other publishing methods, you can cite it as Tafakkori (2022) (in text) and refer to it as follows: Tafakkori, K. (2022). Pricing with linear demand function using Gekko in Python. Supply Chain Data Analytics. url: https://www.supplychaindataanalytics.com/pricing-with-linear-demand-function-using-gekko-in-python/
Industrial engineer focusing on leveraging optimization methods and artificial intelligence technologies using multiple programming languages to empower a business to achieve its goals!