优化 回归_使用回归优化产品价格
優(yōu)化 回歸
應(yīng)用數(shù)據(jù)科學(xué) (Applied data science)
Price and quantity are two fundamental measures that determine the bottom line of every business, and setting the right price is one of the most important decisions a company can make. Under-pricing hurts the company’s revenue if consumers are willing to pay more and, on the other hand, over-pricing can hurt in a similar fashion if consumers are less inclined to buy the product at a higher price.
價(jià)格和數(shù)量是確定每項(xiàng)業(yè)務(wù)底線的兩個(gè)基本指標(biāo),而設(shè)定正確的價(jià)格是公司可以做出的最重要決定之一。 如果消費(fèi)者愿意支付更高的價(jià)格,定價(jià)過(guò)低會(huì)損害公司的收入;另一方面,如果消費(fèi)者不太愿意以更高的價(jià)格購(gòu)買產(chǎn)品,那么定價(jià)過(guò)高也會(huì)以類似的方式受到損害。
So given the tricky relationship between price and sales, where is the sweet spot — the optimum price — that maximizes product sales and earns most profit?
因此,考慮到價(jià)格與銷售之間的棘手關(guān)系,最佳產(chǎn)品的最佳銷售點(diǎn)在哪里?這可以最大化產(chǎn)品的銷售并獲得最大的利潤(rùn)?
The purpose of this article is to answer this question by implementing a combination of the economic theory and a regression algorithm in Python environment.
本文的目的是通過(guò)在Python環(huán)境中實(shí)現(xiàn)經(jīng)濟(jì)理論和回歸算法的結(jié)合來(lái)回答這個(gè)問(wèn)題。
1.資料 (1. Data)
We are optimizing a future price based on the relationship between historical price and sales, so the first thing we need is the past data on these two indicators. For this exercise, I’m using a time series data on historical beef sales and corresponding unit prices.
我們正在根據(jù)歷史價(jià)格和銷售量之間的關(guān)系來(lái)優(yōu)化未來(lái)價(jià)格,因此我們需要的第一件事是這兩個(gè)指標(biāo)的過(guò)去數(shù)據(jù)。 在本練習(xí)中,我使用有關(guān)歷史牛肉銷售量和相應(yīng)單價(jià)的時(shí)間序列數(shù)據(jù)。
# load dataimport pandas as pd
beef = pd# view first few rows
beef.tail(5
The dataset contains a total of 91 observations of quantity-price pairs reported on a quarterly basis.
該數(shù)據(jù)集包含每季度報(bào)告的91個(gè)數(shù)量-價(jià)格對(duì)的觀察值。
It is customary in data science to do exploratory data analysis (EDA), but I’m skipping that part to focus on modeling. Nevertheless, I strongly encourage taking this extra step to make sure you understand the data before building models.
數(shù)據(jù)科學(xué)中通常進(jìn)行探索性數(shù)據(jù)分析(EDA),但我跳過(guò)了這一部分,而只關(guān)注建模。 不過(guò),我強(qiáng)烈建議您采取額外的步驟,以確保您在構(gòu)建模型之前了解數(shù)據(jù)。
2.圖書館 (2. Libraries)
We need to import libraries for three reasons: manipulating data, building the model, and visualizing the functions.
我們需要導(dǎo)入庫(kù)的原因有三個(gè):處理數(shù)據(jù),構(gòu)建模型和可視化功能。
We are importing numpy and pandas for creating and manipulating table, mtplotlib and seaborn for visualization and statsmodels API to build and run the regression model.
我們將導(dǎo)入numpy和pandas用于創(chuàng)建和操作表格, mtplotlib和seaborn用于可視化和statsmodels API以構(gòu)建和運(yùn)行回歸模型。
import numpy as npfrom pandas import DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
from statsmodels.formula.api import ols
%matplotlib inline
2.定義利潤(rùn)函數(shù) (2. Defining the profit function)
We know that revenue depends on the quantity sold and the unit price of products.
我們知道,收入取決于出售的數(shù)量和產(chǎn)品的單價(jià)。
We also know that profit is calculated by netting out costs from revenue.
我們也知道,利潤(rùn)是通過(guò)從收入中扣除成本來(lái)計(jì)算的。
Putting these two together we get the following equations:
將這兩個(gè)放在一起,我們得到以下方程式:
# revenuerevenue = quantity * price # eq (1)# profit
profit = revenue - cost # eq (2)
We can rewrite the profit function by combining eq. #1 and 2 as follows:
我們可以結(jié)合等式來(lái)重寫利潤(rùn)函數(shù)。 #1和2如下:
# revised profit functionprofit = quantity * price - cost # eq (3)
Eq #3 tells us that we need three pieces of information to calculate profit: quantity, price and cost.
方程3告訴我們,我們需要三項(xiàng)信息來(lái)計(jì)算利潤(rùn):數(shù)量,價(jià)格和成本。
3.定義需求函數(shù) (3. Defining the demand function)
We first need to establish the relationship between quantity and price — the demand function. This demand function is estimated from a “demand curve” based on the linear relationship between price and quantity.
我們首先需要建立數(shù)量和價(jià)格之間的關(guān)系-需求函數(shù)。 根據(jù)價(jià)格和數(shù)量之間的線性關(guān)系,根據(jù)“需求曲線”估算此需求函數(shù)。
# demand curvesns.lmplot(x = "Price", y = "Quantity",
data = beef, fig_reg = True, size = 4)
To find that demand curve we will fit an Ordinary Least Square (OLS) regression model.
為了找到需求曲線,我們將擬合普通最小二乘(OLS)回歸模型。
# fit OLS modelmodel = ols("Quantity ~ Price", data = beef).fit()# print model summary
print(model.summary())
The following are the regression results with the necessary coefficients needed for further analysis.
以下是回歸結(jié)果以及進(jìn)一步分析所需的必要系數(shù)。
5.找到利潤(rùn)最大化的價(jià)格 (5. Finding the profit-maximizing price)
The coefficient we are looking for is coming from the regression model above — the intercept and the price coefficient — to measure the corresponding sales quantity. We can now plug these values into equation 3.
我們正在尋找的系數(shù)來(lái)自上面的回歸模型(截距和價(jià)格系數(shù)),用于測(cè)量相應(yīng)的銷售量。 現(xiàn)在,我們可以將這些值插入方程式3。
# plugging regression coefficientsquantity = 30.05 - 0.0465 * price # eq (5)# the profit function in eq (3) becomes
profit = (30.05 - 0.0465 * price) * price - cost # eq (6)
The next step is to find the price we are looking for from a range of options. The codes below should be intuitive, but basically what we are doing here is calculating revenue for each price and the corresponding quantity sold.
下一步是從一系列選項(xiàng)中找到我們要尋找的價(jià)格。 下面的代碼應(yīng)該很直觀,但是基本上我們?cè)谶@里要做的是計(jì)算每個(gè)價(jià)格和相應(yīng)銷售數(shù)量的收入。
# a range of diffferent prices to find the optimum onePrice = [320, 330, 340, 350, 360, 370, 380, 390]# assuming a fixed cost
cost = 80Revenue = []for i in Price:
quantity_demanded = 30.05 - 0.0465 * i
# profit function
Revenue.append((i-cost) * quantity_demanded)# create data frame of price and revenue
profit = pd.DataFrame({"Price": Price, "Revenue": Revenue})#plot revenue against price
plt.plot(profit["Price"], profit["Revenue"])
If price and revenue are plotted, we can visually identify the peak of the revenue and find the price that makes the revenue at the highest point on the curve.
如果繪制了價(jià)格和收入,我們可以直觀地識(shí)別收入的峰值,并找到使收入處于曲線最高點(diǎn)的價(jià)格。
So we find that the maximum revenue at different price levels is reached at $3,726 when the price is set at $360.
因此,我們發(fā)現(xiàn),當(dāng)價(jià)格設(shè)為360美元時(shí),在不同價(jià)格水平下的最高收入達(dá)到3,726美元。
# price at which revenue is maximumprofit[profit['Revenue'] == profit[['Revenue'].max()]
總結(jié)和結(jié)論 (Summary and conclusions)
The purpose of this article was to demonstrate how to find the price at which the revenue or profit is maximized using a combination of economic theory and statistical modeling. In the initial steps we defined the demand and profit functions, and then ran a regression to find the parameter values needed to feed into the profit/revenue function. And finally, we checked revenues under different price levels to get the price for the corresponding maximum revenue.
本文的目的是演示如何結(jié)合經(jīng)濟(jì)理論和統(tǒng)計(jì)模型找到使收益或利潤(rùn)最大化的價(jià)格。 在最初的步驟中,我們定義了需求和利潤(rùn)函數(shù),然后進(jìn)行回歸以找到輸入利潤(rùn)/收益函數(shù)所需的參數(shù)值。 最后,我們檢查了不同價(jià)格水平下的收入,以獲得對(duì)應(yīng)的最大收入的價(jià)格。
翻譯自: https://towardsdatascience.com/optimizing-product-price-using-regression-2c17688e65ea
優(yōu)化 回歸
總結(jié)
以上是生活随笔為你收集整理的优化 回归_使用回归优化产品价格的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 梦到自己上班迟到是什么意思
- 下一篇: 梦到亲人跳水是什么意思