Linear Regression Example
此示例仅使用diabetes数据集的第一个特征,以说明此回归技术的二维图。可以在图中看到直线,显示线性回归如何尝试绘制直线,该线将最佳地最小化数据集中观察到的响应之间的残差平方和线性近似预测的响应。
The coefficients(系数指标):
the residual sum of squares(残差平方和),the variance score(方差)
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets, linear_model
from sklearn.metrics import mean_squared_error, r2_score
# 载入糖尿病数据集
diabetes = datasets.load_diabetes()
# Use only one feature
diabetes_X = diabetes.data[:, np.newaxis, 2]
# Split the data into training/testing sets
diabetes_X_train = diabetes_X[:-20]
diabetes_X_test = diabetes_X[-20:]
# Split the targets