前言
本文只是记录回归分析中所可能使用到的代码,具体的知识点及调参方法并未记录
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn import datasets,linear_model
import pandas as pd
data = pd.read_csv("data.csv“)
y = data.iloc[:,2]
x = data.iloc[:, 3:5]
# 训练数据
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.25, random_state = 1)
regr = linear_model.LinearRegression()
regr.fit(x_train,y_train)
print('coefficients(b1,b2...):',regr.coef_)
print('intercept(b0):',regr.intercept_)
# 预测数据
y_pred = regr.predict(x_test)
# 查看模型得分
regr.score(x_test, y_test)