1.代码实战

#!/usr/bin/env python
#!_*_ coding:UTF-8 _*_

from sklearn import datasets
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

# 从内置训练数据集中加载房价数据
loaded_data = datasets.load_boston()
data_X = loaded_data.data
data_y = loaded_data.target

model = LinearRegression()
model.fit(data_X, data_y)

print model.coef_
print model.intercept_
print model.get_params()
print model.score(data_X, data_y)

结果:

[ -1.07170557e-01   4.63952195e-02   2.08602395e-02   2.68856140e+00
/Users/liudaoqiang/PycharmProjects/numpy/venv/lib/python2.7/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.
  -1.77957587e+01   3.80475246e+00   7.51061703e-04  -1.47575880e+00
  warnings.warn(mesg, RuntimeWarning)
   3.05655038e-01  -1.23293463e-02  -9.53463555e-01   9.39251272e-03
  -5.25466633e-01]
36.4911032804
{'copy_X': True, 'normalize': False, 'n_jobs': 1, 'fit_intercept': True}
0.740607742865
05-08 08:20