线性回归2020年天猫双十一销量

# 认为天猫销量和年份之间存在函数关系 一元二次,一元三次

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

years = np.arange(2009,2020)
years
#array([2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019])

sales = np.array([0.5,9.36,52,191,352,571,912,1207,1682.69,2135,2684])
sales
#array([5.00000e-01, 9.36000e+00, 5.20000e+01, 1.91000e+02, 3.52000e+02,5.71000e+02, 9.12000e+02, 1.20700e+03, 1.68269e+03, 2.13500e+03,2.68400e+03])

plt.scatter(years,sales,c = 'red',marker='*',s = 80)

在这里插入图片描述

X = (years - 2008).reshape(-1,1)
X
#array([[ 1],[ 2],[ 3],[ 4],[ 5],[ 6],[ 7],[ 8],[ 9],[10],[11]])

y = sales
y
#array([5.00000e-01, 9.36000e+00, 5.20000e+01, 1.91000e+02, 3.52000e+02,5.71000e+02, 9.12000e+02, 1.20700e+03, 1.68269e+03, 2.13500e+03,2.68400e+03])

from sklearn.linear_model import LinearRegression

lr = LinearRegression(fit_intercept=True)
lr.fit(X,y)
# weight 权重
w = lr.coef_[0]
# bias 偏差
b = lr.intercept_
display(w,b)
plt.scatter(years -2008,sales,c = 'red',marker='*',s = 80)
x = np.linspace(1,12,50)
plt.plot(x,w*x + b,c = 'green')

在这里插入图片描述

X2 = np.concatenate([X**2,X],axis= 1)
X2.shape
#(11, 2)

# 假定函数是一元二次f(x) = w1*x**2 + w2*x + b
lr = LinearRegression(fit_intercept=True)
X2 = np.concatenate([X**2,X],axis= 1)

lr.fit(X2,y)
# weight 权重
w1,w2 = lr.coef_
# bias 偏差
b = lr.intercept_
display(w1,w2,b)
plt.scatter(years -2008,sales,c = 'red',marker='*',s = 80)
x = np.linspace(1,12,50)
f = lambda x :w1*x**2 + w2*x + b
plt.plot(x,f(x),c = 'green')
# 2009 -----1
# 2010 -----2
# 2020 -----12
print('2020年天猫双十一销量预测:',np.round(f(12),1))

在这里插入图片描述

# 假定函数是一元三次f(x) = w1*x**3 + w2*x**2 + w3*x + b
lr = LinearRegression(fit_intercept=True)
X3 = np.concatenate([X**3,X**2,X],axis= 1)

lr.fit(X3,y)
# weight 权重
w1,w2,w3 = lr.coef_
# bias 偏差
b = lr.intercept_
plt.scatter(years -2008,sales,c = 'red',marker='*',s = 80)
x = np.linspace(1,12,50)
f = lambda x :w1*x**3 + w2*x**2 + w3*x + b
plt.plot(x,f(x),c = 'green')

# 2009 -----1
# 2010 -----2
# 2020 -----12
print('2020年天猫双十一销量预测:',np.round(f(12),1))

在这里插入图片描述

# 瑞幸咖啡,30K
# 本科,华为3年,测试,华为的外包
# 线性回归,预测咖啡销量
# 提前进货,大概,货物积存,占用现金流

# 推荐系统,效益,每日成交量500万
# 不好,100万
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值