当前位置:网站首页>Initial linear regression
Initial linear regression
2022-06-28 02:50:00 【m0_ sixty-one million eight hundred and eleven thousand three h】
One . use Excel In the data analysis function, do linear regression
1. take 20 Group data

2. take 200 Group data

3. take 2000 Group data

Two . use jupyter Programming ( Without the help of third-party libraries ), Linear regression with least square method
1.python Least squares source code
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
points = np.genfromtxt("D:/wh.csv",delimiter=",")
# take wh.csv The data in the file is assigned to points
# take points The data in are assigned to x,y, Find regression equation y=ax+b
x=points[1:21,1];
y=points[1:21,2];
pccs = np.corrcoef(x, y)
c,d=pccs
e,f=c
x_mean = np.mean(x)
y_mean = np.mean(y)
xsize = x.size
zi = (x * y).sum() - xsize * x_mean *y_mean
mu = (x ** 2).sum() - xsize * x_mean ** 2
a = zi / mu
b = y_mean - a * x_mean
a = np.around(a,decimals=2)
b = np.around(b,decimals=2)
print(f' Regression line equation :y = {a}x + {b}')
print(f' The correlation coefficient is 0 {f}')
# Using third party libraries skleran Draw a fit curve
y1 = a*x + b
plt.scatter(x,y)
plt.plot(x,y1,c='r')
2. take 20 Group data

3. take 200 Group data

4. take 2000 Group data

3、 ... and . use jupyter Programming , With the help of skleran Do linear regression
1.python With the help of skleran Source code
from sklearn import linear_model # Express , You can call sklearn Medium linear_model The module performs linear regression .
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
data = np.genfromtxt("wh.csv",delimiter=",")
data1=data[1:21]# Change the value according to the data taken
x=[example[1] for example in data1]
y=[example[2] for example in data1]
pccs = np.corrcoef(x, y)
c,d=pccs
e,f=c
X = np.asarray(x).reshape(-1, 1)
Y = np.asarray(y).reshape(-1, 1)
model = linear_model.LinearRegression()
model.fit(X,Y)
b=model.intercept_[0] # intercept
a=model.coef_[0]# Coefficient of linear model
a1=a[0]
print(f' Regression line equation :y = {a1}x + {b}')
print(f' The correlation coefficient is 0 {f}')
y1 = a1*X + b
plt.scatter(X,Y)
plt.plot(x,y1,c='r')
2. take 20 Group data

3. take 200 Group data

4. take 2000 Group data

Compare : It can be seen from the three ways that the regression equation is generally the same , There are some differences in the correlation coefficient
边栏推荐
- The first place on the list - the carrying rate of front-end equipment is up to 10%, and the top 10 suppliers of digital key solutions
- 第三批入围企业公示!年度TOP100智能网联供应商评选
- Prometheus 2.27.0 新特性
- Data governance and data standards
- MySQL query related knowledge (advanced level 7: sub query
- 迪赛智慧数——柱状图(折柱混合图):2021年毕业季租房价格和房租收入比
- [today in history] June 1: Napster was founded; MS-DOS original author was born; Google sells Google SketchUp
- 【方块编码】基于matlab的图像方块编码仿真
- 贪吃蛇 C语言
- 【历史上的今天】6 月 20 日:MP3 之父出生;富士通成立;谷歌收购 Dropcam
猜你喜欢

STM32的C语言与汇编语言混合编程

【历史上的今天】6 月 8 日:万维网之父诞生;PHP 公开发布;iPhone 4 问世

【历史上的今天】6 月 24 日:网易成立;首届消费电子展召开;世界上第一次网络直播

字节跳动面试官:一张图片占据的内存大小是如何计算

把腾讯搬上云:云服务器 CVM 的半部进化史

云原生(三十) | Kubernetes篇之应用商店-Helm

【历史上的今天】6 月 13 日:分组交换网路的“亲子纠纷”;博弈论创始人出生;交互式电视初现雏形

如何判断线程池已经执行完所有任务了?

Character interception triplets of data warehouse: substrb, substr, substring

Intel Ruixuan A380 graphics card will be launched in China
随机推荐
Digital intelligence learning Lake Warehouse Integration Practice and exploration
Design e-commerce seckill system
横向滚动的RecycleView一屏显示五个半,低于五个平均分布
Reprinted article: the digital economy generates strong demand for computing power Intel releases a number of innovative technologies to tap the potential of computing power
Is it safe for qiniu to open an account? How do I open an account online?
What if win11 cannot use dynamic wallpaper? Solution of win11 without dynamic wallpaper
win11如何添加打印机和扫描仪?win11添加打印机和扫描仪的设置
初始线性回归
[2D code image correction and enhancement] simulation of 2D code image correction and enhancement processing based on MATLAB
Win11 cannot create a new text document? Solution to win11 right click failure to create a new text document
What if win11 can't drag an image to the taskbar software to open it quickly
High reliability application knowledge map of Architecture -- the path of architecture evolution
Win11 ne peut pas faire glisser l'image sur le logiciel de la barre des tâches
MFC CString互转LPVOID
I forgot my cell phone today
SQL报了一个不常见的错误,让新来的实习生懵了
[block coding] simulation of image block coding based on MATLAB
[today in history] June 8: the father of the world wide web was born; PHP public release; IPhone 4 comes out
在线JSON转PlainText工具
How does win11 add printers and scanners? Win11 add printer and scanner settings