1

I am using the Sklearn to do the linear regression for a set of stock price data, after I normalized the data, the MSE all becomes 0.
Why I get all MSE 0? and please help me, somebody said it's because the model problem.. but I am python newbie, and really need help, thanks in advance!

here is one row example in the dataset:

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

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

The code:

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)  

fill in missing value with median

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)

normalized the stock data

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)

result:

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

Average accuracy for Linear Regression: 0.0                                              
Tom Ron
  • 5,906
  • 3
  • 22
  • 38
John L
  • 11
  • 2

0 Answers0