sklearn学习 -- 线性回归 LinearRegression

from sklearn import datasets
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split

load_data = datasets.load_boston()    # 波士顿房价数据集

data_x = load_data.data    # 特征
data_y = load_data.target    # 标签

train_x, test_x, train_y, test_y = train_test_split(data_x, data_y, test_size=0.3)

lr = LinearRegression()
lr.fit(train_x, train_y)    # 训练

print(lr.predict(test_x[:4, :]))    # 预测值
print(test_y[:4])    # 真实值

print(lr.score(test_x, test_y))    # 得分,越接近1越好

 

你可能感兴趣的:(sklearn,机器学习)