model 常用属性和功能

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)

# model 属性
print(model.coef_) # 关于x的参数
print('****************************')
print(model.intercept_)# 关于y的参数
print('****************************')
print(model.get_params())
print('****************************')
# 判断训练后的模型精确度
print(model.score(data_X, data_y))

结果

[-1.07170557e-01 4.63952195e-02 2.08602395e-02 2.68856140e+00
-1.77957587e+01 3.80475246e+00 7.51061703e-04 -1.47575880e+00
3.05655038e-01 -1.23293463e-02 -9.53463555e-01 9.39251272e-03
-5.25466633e-01]


36.4911032803636


{‘n_jobs’: 1, ‘copy_X’: True, ‘normalize’: False, ‘fit_intercept’: True}


0.7406077428649428

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