读取文件
import pandas as pd
import numpy as np
pd=pd.read_excel('test3.xlsx')
pd
样本 X1 X2 X3 X4 X5 Y
0 1 3.18 1.15 9.4 17.6 3.00 0.7
1 2 3.80 0.79 5.1 30.5 3.80 0.7
2 3 3.60 1.10 9.2 9.1 3.65 1.0
3 4 2.73 0.73 14.5 12.8 4.68 1.1
4 5 3.40 1.48 7.6 16.5 4.50 1.5
5 6 3.20 1.00 10.8 10.1 8.10 2.6
6 7 2.60 0.61 7.3 16.1 16.16 2.7
7 8 4.10 2.30 3.7 17.8 6.70 3.1
8 9 3.72 1.94 9.9 36.1 4.10 6.1
9 10 4.10 1.66 8.2 29.4 13.00 9.6
10 11 3.35 1.25 7.8 27.8 10.50 10.9
11 12 3.31 1.81 10.7 9.3 10.90 11.9
12 13 3.60 1.40 24.6 12.6 12.76 12.7
13 14 3.50 1.39 21.3 41.1 10.00 14.7
14 15 4.75 2.40 26.2 42.5 16.40 21.3
求线性回归关系的判定系数
x=pd.iloc[:,1:6].values
y=pd.iloc[:,6].values
x
from sklearn.linear_model import LinearRegression as LR
lr=LR()
lr.fit(x,y)
Slr=lr.score(x,y)
c_x=lr.coef_
c_b=lr.intercept_
x1=np.array([4,1.5,10,17,9])
x1=x1.reshape(1,5)
R1=lr.pre