# 数模打卡第四天–线性回归

## 一元线性回归

### 例题

数据：
x=[6,8,10,14,18];
y=[7,9,13,17.5,18];


matlab代码如下：

x=[6,8,10,14,18];
y=[7,9,13,17.5,18];
N=length(x);%求取x向量的长度
for i=1:N
plot(x(i),y(i),'or');
hold on
end


[p,s]=polyfit(x,y,1)%代码中“1”为拟合的阶数


## 多元回归

### 例题

“题中本来有29组数据，为了方便输入数据，这里作者将其改为10组数据”

%开始多元回归
clear all
clc
x1=[54.89,72.49,53.81,64.74,58.80,43.67,54.89,86.12,60.35,54.04];
x2=[30.86,42.61,52.86,39.18,37.67,26.18,30.86,43.79,38.20,34.23];
x3=[448.70,467.30,425.61,469.80,456.55,395.78,448.70,440.13,394.40,405.60];
x4=[0.012,0.008,0.004,0.005,0.012,0.001,0.012,0.017,0.001,0.008];
x5=[1.010,1.640,1.220,1.220,1.010,0.594,1.010,1.770,1.440,1.300];
y=[13.50,13.00,13.75,14.00,14.25,12.75,12.50,12.25,12.00,11.75];
save data x1 x2 x3 x4 x5 y%保存数据
y=[y'];
x=[ones(size(x1')),x1',x2',x3',x4',x5'];
[b,bint,r,rint,stats]=regress(y,x)


02-23 1万+
03-04 1301
09-14 177
09-15 957
05-19 954
11-30 102
06-23 31
07-13 123
06-18 53

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

¥2 ¥4 ¥6 ¥10 ¥20

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