優化 回歸_使用回歸優化產品價格

優化 回歸

應用數據科學 (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.

價格和數量是確定每項業務底線的兩個基本指標,而設定正確的價格是公司可以做出的最重要決定之一。 如果消費者愿意支付更高的價格,定價過低會損害公司的收入;另一方面,如果消費者不太愿意以更高的價格購買產品,那么定價過高也會以類似的方式受到損害。

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?

因此,考慮到價格與銷售之間的棘手關系,最佳產品的最佳銷售點在哪里?這可以最大化產品的銷售并獲得最大的利潤?

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.

本文的目的是通過在Python環境中實現經濟理論和回歸算法的結合來回答這個問題。

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.

我們正在根據歷史價格和銷售量之間的關系來優化未來價格,因此我們需要的第一件事是這兩個指標的過去數據。 在本練習中,我使用有關歷史牛肉銷售量和相應單價的時間序列數據。

# load data
import pandas as pd
beef = pd# view first few rows
beef.tail(5
Image for post

The dataset contains a total of 91 observations of quantity-price pairs reported on a quarterly basis.

該數據集包含每季度報告的91個數量-價格對的觀察值。

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.

數據科學中通常進行探索性數據分析(EDA),但我跳過了這一部分,而只關注建模。 不過,我強烈建議您采取額外的步驟,以確保您在構建模型之前了解數據。

2.圖書館 (2. Libraries)

We need to import libraries for three reasons: manipulating data, building the model, and visualizing the functions.

我們需要導入庫的原因有三個:處理數據,構建模型和可視化功能。

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.

我們將導入numpypandas用于創建和操作表格, mtplotlibseaborn用于可視化和statsmodels API以構建和運行回歸模型。

import numpy as np
from pandas import DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
from statsmodels.formula.api import ols
%matplotlib inline

2.定義利潤函數 (2. Defining the profit function)

We know that revenue depends on the quantity sold and the unit price of products.

我們知道,收入取決于出售的數量和產品的單價。

We also know that profit is calculated by netting out costs from revenue.

我們也知道,利潤是通過從收入中扣除成本來計算的。

Putting these two together we get the following equations:

將這兩個放在一起,我們得到以下方程式:

# revenue
revenue = quantity * price # eq (1)# profit
profit = revenue - cost # eq (2)

We can rewrite the profit function by combining eq. #1 and 2 as follows:

我們可以結合等式來重寫利潤函數。 #1和2如下:

# revised profit function
profit = quantity * price - cost # eq (3)

Eq #3 tells us that we need three pieces of information to calculate profit: quantity, price and cost.

方程3告訴我們,我們需要三項信息來計算利潤:數量,價格和成本。

3.定義需求函數 (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.

我們首先需要建立數量和價格之間的關系-需求函數。 根據價格和數量之間的線性關系,根據“需求曲線”估算此需求函數。

# demand curve
sns.lmplot(x = "Price", y = "Quantity",
data = beef, fig_reg = True, size = 4)
Image for post

To find that demand curve we will fit an Ordinary Least Square (OLS) regression model.

為了找到需求曲線,我們將擬合普通最小二乘(OLS)回歸模型。

# fit OLS model
model = 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.

以下是回歸結果以及進一步分析所需的必要系數。

Image for post

5.找到利潤最大化的價格 (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.

我們正在尋找的系數來自上面的回歸模型(截距和價格系數),用于測量相應的銷售量。 現在,我們可以將這些值插入方程式3。

# plugging regression coefficients
quantity = 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.

下一步是從一系列選項中找到我們要尋找的價格。 下面的代碼應該很直觀,但是基本上我們在這里要做的是計算每個價格和相應銷售數量的收入。

# a range of diffferent prices to find the optimum one
Price = [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.

如果繪制了價格和收入,我們可以直觀地識別收入的峰值,并找到使收入處于曲線最高點的價格。

Image for post

So we find that the maximum revenue at different price levels is reached at $3,726 when the price is set at $360.

因此,我們發現,當價格設為360美元時,在不同價格水平下的最高收入達到3,726美元。

# price at which revenue is maximum
profit[profit['Revenue'] == profit[['Revenue'].max()]
Image for post

總結和結論 (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.

本文的目的是演示如何結合經濟理論和統計模型找到使收益或利潤最大化的價格。 在最初的步驟中,我們定義了需求和利潤函數,然后進行回歸以找到輸入利潤/收益函數所需的參數值。 最后,我們檢查了不同價格水平下的收入,以獲得對應的最大收入的價格。

翻譯自: https://towardsdatascience.com/optimizing-product-price-using-regression-2c17688e65ea

優化 回歸

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389422.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389422.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389422.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Node.js——異步上傳文件

前臺代碼 submit() {var file this.$refs.fileUpload.files[0];var formData new FormData();formData.append("file", file);formData.append("username", this.username);formData.append("password", this.password);axios.post("http…

用 JavaScript 的方式理解遞歸

原文地址 1. 遞歸是啥? 遞歸概念很簡單,“自己調用自己”(下面以函數為例)。 在分析遞歸之前,需要了解下 JavaScript 中“壓棧”(call stack) 概念。 2. 壓棧與出棧 棧是什么?可以理解是在內存…

PyTorch官方教程中文版:Pytorch之圖像篇

微調基于 torchvision 0.3的目標檢測模型 """ 為數據集編寫類 """ import os import numpy as np import torch from PIL import Imageclass PennFudanDataset(object):def __init__(self, root, transforms):self.root rootself.transforms …

大數據數據科學家常用面試題_進行數據科學工作面試

大數據數據科學家常用面試題During my time as a Data Scientist, I had the chance to interview my fair share of candidates for data-related roles. While doing this, I started noticing a pattern: some kinds of (simple) mistakes were overwhelmingly frequent amo…

scrapy模擬模擬點擊_模擬大流行

scrapy模擬模擬點擊復雜系統 (Complex Systems) In our daily life, we encounter many complex systems where individuals are interacting with each other such as the stock market or rush hour traffic. Finding appropriate models for these complex systems may give…

公司想申請網易企業電子郵箱,怎么樣?

不論公司屬于哪個行業,選擇企業郵箱,交互界面友好度、穩定性、安全性都是選擇郵箱所必須考慮的因素。網易企業郵箱郵箱方面已有21年的運營經驗,是國內資歷最高的電子郵箱,在各個方面都非常成熟完善。 從交互界面友好度來看&#x…

莫煩Matplotlib可視化第二章基本使用代碼學習

基本用法 import matplotlib.pyplot as plt import numpy as np""" 2.1基本用法 """ # x np.linspace(-1,1,50) #[-1,1]50個點 # #y 2*x 1 # # y x**2 # plt.plot(x,y) #注意:x,y順序不能反 # plt.show()"""…

vue.js python_使用Python和Vue.js自動化報告過程

vue.js pythonIf your organization does not have a data visualization solution like Tableau or PowerBI nor means to host a server to deploy open source solutions like Dash then you are probably stuck doing reports with Excel or exporting your notebooks.如果…

plsql中導入csvs_在命令行中使用sql分析csvs

plsql中導入csvsIf you are familiar with coding in SQL, there is a strong chance you do it in PgAdmin, MySQL, BigQuery, SQL Server, etc. But there are times you just want to use your SQL skills for quick analysis on a small/medium sized dataset.如果您熟悉SQ…

第十八篇 Linux環境下常用軟件安裝和使用指南

提醒:如果之后要安裝virtualenvwrapper的話,可以直接跳到安裝virtualenvwrapper的方法,而不需要先安裝好virtualenv安裝virtualenv和生成虛擬環境安裝virtualenv:yum -y install python-virtualenv生成虛擬環境:先切換…

莫煩Matplotlib可視化第三章畫圖種類代碼學習

3.1散點圖 import matplotlib.pyplot as plt import numpy as npn 1024 X np.random.normal(0,1,n) Y np.random.normal(0,1,n) T np.arctan2(Y,X) #用于計算顏色plt.scatter(X,Y,s75,cT,alpha0.5)#alpha是透明度 #plt.scatter(np.arange(5),np.arange(5)) #一條線的散點…

計算機科學必讀書籍_5篇關于數據科學家的產品分類必讀文章

計算機科學必讀書籍Product categorization/product classification is the organization of products into their respective departments or categories. As well, a large part of the process is the design of the product taxonomy as a whole.產品分類/產品分類是將產品…

es6解決回調地獄問題

本文摘抄自阮一峰老師的 http://es6.ruanyifeng.com/#docs/generator-async 異步 所謂"異步",簡單說就是一個任務不是連續完成的,可以理解成該任務被人為分成兩段,先執行第一段,然后轉而執行其他任務,等做好…

交替最小二乘矩陣分解_使用交替最小二乘矩陣分解與pyspark建立推薦系統

交替最小二乘矩陣分解pyspark上的動手推薦系統 (Hands-on recommender system on pyspark) Recommender System is an information filtering tool that seeks to predict which product a user will like, and based on that, recommends a few products to the users. For ex…

莫煩Matplotlib可視化第四章多圖合并顯示代碼學習

4.1Subplot多合一顯示 import matplotlib.pyplot as plt import numpy as npplt.figure() """ 每個圖占一個位置 """ # plt.subplot(2,2,1) #將畫板分成兩行兩列,選取第一個位置,可以去掉逗號 # plt.plot([0,1],[0,1]) # # plt.su…

python 網頁編程_通過Python編程檢索網頁

python 網頁編程The internet and the World Wide Web (WWW), is probably the most prominent source of information today. Most of that information is retrievable through HTTP. HTTP was invented originally to share pages of hypertext (hence the name Hypertext T…

Python+Selenium自動化篇-5-獲取頁面信息

1.獲取頁面title title:獲取當前頁面的標題顯示的字段from selenium import webdriver import time browser webdriver.Chrome() browser.get(https://www.baidu.com) #打印網頁標題 print(browser.title) #輸出內容:百度一下,你就知道 2.…

火種 ctf_分析我的火種數據

火種 ctfOriginally published at https://www.linkedin.com on March 27, 2020 (data up to date as of March 20, 2020).最初于 2020年3月27日 在 https://www.linkedin.com 上 發布 (數據截至2020年3月20日)。 Day 3 of social distancing.社會疏離的第三天。 As I sit on…

莫煩Matplotlib可視化第五章動畫代碼學習

5.1 Animation 動畫 import numpy as np import matplotlib.pyplot as plt from matplotlib import animationfig,ax plt.subplots()x np.arange(0,2*np.pi,0.01) line, ax.plot(x,np.sin(x))def animate(i):line.set_ydata(np.sin(xi/10))return line,def init():line.set…

data studio_面向營銷人員的Data Studio —報表指南

data studioIn this guide, we describe both the theoretical and practical sides of reporting with Google Data Studio. You can use this guide as a comprehensive cheat sheet in your everyday marketing.在本指南中,我們描述了使用Google Data Studio進行…