多变量的线性回归问题
1 import csv 2 import numpy as np 3 import pandas as pd 4 from sklearn import datasets,linear_model 5 6 with open("car.csv","r") as f: 7 data = list(csv.reader(f)) 8 data_X = [row[:2] for row in data[1:]] 9 data_Y = [row[-1] for row in data[1:]] 10 regression = linear_model.LinearRegression() 11 regression.fit(data_X,data_Y) 12 #B的值 13 print(regression.coef_) 14 #截距 15 print(regression.intercept_) 16 #测试 17 xPred = np.array([102,6]) 18 yPred = regression.predict(xPred.reshape(1,-1)) 19 print(yPred)
car.csv文件地址链接:https://pan.baidu.com/s/1pM4jem3 密码:e22s
谢谢观看!