当前位置:网站首页>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()
边栏推荐
- Reading the paper [sensor enlarged egocentric video captioning with dynamic modal attention]
- [paper reading] semi supervised left atrium segmentation with mutual consistency training
- Message queuing: how to ensure that messages are not lost
- Win configuration PM2 boot auto start node project
- [论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training
- The 2022 China low / no code Market Research and model selection evaluation report was released
- Lombok plug-in
- zabbix_ Get test database failed
- Leakage relay jelr-250fg
- AI人脸编辑让Lena微笑
猜你喜欢
C nullable type
Unity keeps the camera behind and above the player
Distributed global ID generation scheme
I didn't know it until I graduated -- the principle of HowNet duplication check and examples of weight reduction
Web architecture design process
消息队列:消息积压如何处理?
Randomly generate session_ id
Harmonyos practice - Introduction to development, analysis of atomized services
不同网段之间实现GDB远程调试功能
Digital innovation driven guide
随机推荐
Realize GDB remote debugging function between different network segments
集群、分布式、微服務的區別和介紹
消息队列:消息积压如何处理?
爬虫练习题(三)
Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
分布式事务解决方案之2PC
原生小程序 之 input切换 text与password类型
Bat instruction processing details
Educational Codeforces Round 22 B. The Golden Age
盘点国内有哪些EDA公司?
bat 批示处理详解
Paper reading [MM21 pre training for video understanding challenge:video captioning with pre training techniqu]
2pc of distributed transaction solution
4. Object mapping Mapster
sql优化常用技巧及理解
Hcip seventh operation
nodejs获取客户端ip
nVisual网络可视化
线性回归
淘寶商品詳情頁API接口、淘寶商品列錶API接口,淘寶商品銷量API接口,淘寶APP詳情API接口,淘寶詳情API接口