LinearRegression in sklearn

➜ test ✗ cat linearRegression.py
from sklearn import linear_model

# 训练数据集
X = [[0, 0], [1, 1], [2, 2]]
Y = [0, 1, 2]

# 创建线性回归对象
clf = linear_model.LinearRegression()

# 拟合数据
clf.fit(X, Y)

# 输出拟合出来的系数
print(clf.coef_)

# 输出拟合出来的截距
print(clf.intercept_)

# 预测结果
print(clf.predict([[3, 4]]))

# 输出训练集的R^2得分
print(clf.score(X, Y))
➜ test ✗ python3 linearRegression.py
/usr/local/lib/python3.6/site-packages/scipy/linalg/basic.py:1226: RuntimeWarning: internal gelsd driver lwork query error, required iwork dimension not returned. This is likely the result of LAPACK bug 0038, fixed in LAPACK 3.2.2 (released July 21, 2010). Falling back to 'gelss' driver.
  warnings.warn(mesg, RuntimeWarning)
[0.5 0.5]
1.1102230246251565e-16
[3.5]
1.0