使用OLS做回归
#使用OLS做多元线性回归拟合
from sklearn import linear_model,cross_validation, feature_selection,preprocessing
import statsmodels.formula.api as sm
from statsmodels.tools.eval_measures import mse
from statsmodels.tools.tools import add_constant
from sklearn.metrics import mean_squared_error
X = b_data.values.copy()
X_train, X_valid, y_train, y_valid =
cross_validation.train_test_split( X[:, :-1], X[:, -1],train_size=0.80)
result = sm.OLS( y_train, add_constant(X_train) ).fit()
result.summary()
https://www.datarobot.com/blog/ordinary-least-squares-in-python/
解读summary结果
summary结果中提供了很多关于拟合的信息,下面是这些描述信息的含义:
第一个表左边部分是关于拟合的基本信息:
Element | Description | 中文描述(个人翻译,如有错误请留言指出) |
Dep. Variable | Which variable is the response in the model | 响应变量/独立变量 y |
Model | What model you are using in the fit | 用来做拟合的模型 |
Method | How the parameters of the model were calculated | 模型参数的计算方法 |
No. Observat |