我正在使用 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