sklearn.linear_model.LinearRegression
最常见的普通线性回归
__init__()
'''
参数:
fit_intercept: bool, 默认为True, 是否计算线性模型的截距, 如果为Fasle, 要求样本是centered之后的;
normalize: bool, 默认为False, 如果为True, 样本X在回归之前会进行标准化; 当fit_intercept设置为False时, 该参数被忽略.
copy_X: bool, 默认为True, 是否copy X, 否则X会被覆盖;
n_jobs: 使用的CPU的个数, 默认为1. -1则使用所有CPU.
属性:
coef_: 线性模型的W参数, shape为(n_targets, n_features);
intercept_: 线性模型的b参数.
'''
fit()
作用:
训练模型
参数:
X: 训练特征数据, shape为[n_samples,n_features];
Y: 训练target数据, shape为[n_samples, n_targets];
sample_weight: 每个样本的权重, shape为[n_samples].返回:
self实例
get_params()
作用:
获取该estimator的参数.
参数:
deep: bool, 默认为True.
返回:
参数字典:
{'normalize': False, 'copy_X': True, 'fit_intercept': True, 'n_jobs': 1}
predict()
作用:
给与样本, 进行预测.
参数:
X: 批量的需要预测的样本, shape为(n_samples, n_features)
返回:
预测结果, shape为(n_samples,)
score()
作用:
返回该线性模型的评分. 评分方式为
score=(1-u/v)
, 其中u是所有样本的平方误差之和((y_true - y_pred) ** 2).sum()
, v是所有样本的真实结果的方差((y_true - y_true.mean()) ** 2).sum()
, 最好的模型评分为1.0, 差的模型结果可能为负值.参数:
X: 测试集样本, shape为(n_samples, n_features)
y: 测试集真实值, shape为(n_samples, n_outputs)
sample_weight: 每个样本的权重, shape为[n_samples]返回:
float, 模型分数结果.