weixin_43868770
weixin_43868770
2018-12-09 13:42

用sklearn做线性回归, 但数据normalization后,出来MSE全部为0。

  • python
  • 归一化
  • sklearn
  • mse

用sklearn在股票价格数据 做线性回归, 但数据normalization后,出来MSE的结果全部为0。别人说是模型出错了, 但奈何自己是python新手,请求各位帮忙指出其中原因,感谢感谢!!!!

数据是这样子的:

图片说明

这是不加normalization的,

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

LinearRegression=LinearRegression()

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


print (-scores)
print ('Average score for Linear Regression:', np.mean(scores))

结果看起来还算正常:
[ 0.03666889 0.05985924 0.05718805 0.04757506 0.05605501 0.05602068
0.04308263 0.05089644 0.0489978 0.0384472 ]
Average score for Linear Regression: -0.0494790998005

##分割线##

normalization处理过的:

from sklearn.linear_model import LinearRegression
from sklearn import cross_validation


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)

print (-scores)
print ('Average score for Linear Regression:', np.mean(scores))


结果:
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
Average score for Linear Regression: 0.0

别人说是模型出错了, 但奈何自己是python新手,请求各位帮忙指出其中原因,感谢感谢!!!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答

为你推荐

换一换