当前位置:网站首页>linear regression
linear regression
2022-07-07 05:47:00 【Python code doctor】
import numpy as np
from matplotlib import pyplot as plt
# Define training data
x = np.array([0.86, 0.96, 1.12, 1.35, 1.55, 1.63, 1.71, 1.78])
y = np.array([12, 15, 20, 35, 48, 51, 59, 66])
def fit(x,y):
if len(x) != len(y):
return
numerator = 0.0
denominator = 0.0
x_mean = np.mean(x)
y_mean = np.mean(y)
for i in range(len(x)):
numerator += (x[i]-x_mean)*(y[i]-y_mean)
denominator += np.square(x[i]-x_mean)
b0 = numerator / denominator
b1 = y_mean-b0*x_mean
return b0,b1
b0,b1 = fit(x,y)
def predit(x,b0,b1):
return b0*x+b1
# forecast
x_test = np.array([0.75,1.08,1.26,1.51,1.6,1.67,1.85])
y_test = np.array([10,17,27,41,50,64,75])
y_predit = predit(x_test,b0,b1)
# The plot
plt.plot(x,y,'k.')
plt.plot(x_test,y_predit,'g-')
yr = predit(x,b0,b1)
for idx,x in enumerate(x):
plt.plot([x,x],[y[idx],yr[idx]],'r-')
print(predit(1.75,b0,b1))
plt.show()
边栏推荐
- zabbix_ Get test database failed
- EMMC打印cqhci: timeout for tag 10提示分析与解决
- 404 not found service cannot be reached in SAP WebService test
- 原生小程序 之 input切换 text与password类型
- Preliminary practice of niuke.com (9)
- 随机生成session_id
- nVisual网络可视化
- Web authentication API compatible version information
- 【Shell】清理nohup.out文件
- sql查询:将下一行减去上一行,并做相应的计算
猜你喜欢

消息队列:如何确保消息不会丢失

京东商品详情页API接口、京东商品销量API接口、京东商品列表API接口、京东APP详情API接口、京东详情API接口,京东SKU信息接口

JSP setting header information export to excel

SQL query: subtract the previous row from the next row and make corresponding calculations

爬虫练习题(三)

English grammar_ Noun possessive

pytorch_ 01 automatic derivation mechanism

The year of the tiger is coming. Come and make a wish. I heard that the wish will come true

分布式事务介绍

sql查询:将下一行减去上一行,并做相应的计算
随机推荐
Wechat applet Bluetooth connects hardware devices and communicates. Applet Bluetooth automatically reconnects due to abnormal distance. JS realizes CRC check bit
Taobao commodity details page API interface, Taobao commodity list API interface, Taobao commodity sales API interface, Taobao app details API interface, Taobao details API interface
Web authentication API compatible version information
成为资深IC设计工程师的十个阶段,现在的你在哪个阶段 ?
EMMC打印cqhci: timeout for tag 10提示分析与解决
R language [logic control] [mathematical operation]
论文阅读【Open-book Video Captioning with Retrieve-Copy-Generate Network】
make makefile cmake qmake都是什么,有什么区别?
Preliminary practice of niuke.com (9)
什么是消息队列?
R语言【逻辑控制】【数学运算】
判断文件是否为DICOM文件
Introduction to distributed transactions
[binary tree] binary tree path finding
win配置pm2开机自启node项目
An example of multi module collaboration based on NCF
随机生成session_id
404 not found service cannot be reached in SAP WebService test
[reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation
Lombok plug-in