from numpy.linalg import inv
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import linear_model
#读取数据
dataset=pd.read_excel("data.xlsx")
temp=dataset.iloc[:,1:3]
#print(temp)
#print(type(temp))
x=temp.iloc[:,1:3]
#print(x)
y=dataset.iloc[:,1].values.reshape(64,1)
#print(y)
clf=linear_model.LinearRegression()
clf.fit(x,y)
plt.scatter(x,y,c = 'blue',marker = 'o')
x1=[[3],[4],[5.4],[5.6],[6],[6.4],[6.7],[6.8],[7],[7.5],[7.7],[10],[13],[17.9],[23],[25.5],[28.5],[33],[35],[40],[44],[47],[50]]
res1=clf.predict(x1)
plt.plot(x1,res1,'r-')
运行程序结果:
部分数据如下: