sklearn的股票数据线性回归

时间:2018-12-09 14:15:21

标签: python scikit-learn linear-regression normalization mse

我正在使用Sklearn对一组股价数据进行线性回归,将数据标准化后,MSE均变为0。
为什么我的MSE全部为0?并请帮助我,有人说这是因为模型问题。.但是我是python新手,真的需要帮助,在此先感谢!

这是数据集中的一行示例:

tdate ,     stock_id ,   open ,  close ,  high ,  low ,   volume

04/01/2000   ,   1  ,    100  ,   98  ,    101  ,  98  ,   283100

代码:

from sklearn.linear_model import LinearRegression
from sklearn import cross_validation
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import Normalizer
from sklearn.model_selection import train_test_split

stock1= file[['open','close','high','low','volume']].where(file['stock_id'] 
== 1)
X_stock1 = stock1.drop(['close'],axis=1)
y_stock1 = stock1['close']
X_stock1_train, X_stock1_test, y_stock1_train, y_stock1_test = 
train_test_split(X_stock1, y_stock1, train_size=0.8, random_state=42)  

用中位数填写缺失值

X_stock1_train= Imputer(missing_values='NaN', strategy='median', 
axis=0).fit_transform (X_stock1_train)
y_stock1_train=y_stock1_train.reshape(-1,1) 
y_stock1_train=Imputer(missing_values='NaN', strategy='median', axis=0 
).fit_transform (y_stock1_train)

标准化库存数据

transformer=Normalizer().fit(X_stock1_train, y_stock1_train)
X_stock1_train=transformer.transform(X_stock1_train)
y_stock1_train=transformer.transform(y_stock1_train)

LinearRegression=LinearRegression()
scores = cross_validation.cross_val_score(LinearRegression, X_stock1_train,
                                          y_stock1_train, scoring= 'neg_mean_ 
                                          squared_error' , cv=10)

结果:

[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]

Average accuracy for Linear Regression: 0.0                                              

0 个答案:

没有答案