Because this chapter is more difficult to learn, practice this week, the contents of other small partners reference code
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_squared_error,r2_score
data = pd.read_csv('/Users/Documents/car_test.csv')
data.head()
# 查看相关性
cormatrix = data.corr()
print(cormatrix)
x_train,x_test ,y_train,y_test = train_test_split(x,y,test_size = 0.25,random_state = 1)
ss = StandardScaler()
ss.fit(x_train)
x_train_ss = ss.transform(x_train)
x_test_ss = ss.transform(x_test)
lr = LinearRegression()
lr.fit(x_train_ss,y_train)
mean_squared_error(y_test,y_pred)
r2_score(y_test,y_pred)