l19RWhttps://www.yzms.cn/webhtml/list.aspx?ChannelId=1&ClassID=501GKWZ51L0JQH4#python实现线性回归
import numpy as np
import pandas as pd
from numpy.linalg import inv
from numpy import dot
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn import linear_model
# 最小二乘法
def lms(x_train,y_train,x_test):
theta_n = dot(dot(inv(dot(x_train.T, x_train)), x_train.T), y_train) # theta = (X'X)^(-1)X'Y
#print(theta_n)
y_pre = dot(x_test,theta_n)
mse = np.avera