Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to normalize input of neural network predicting stock market [python]

I am trying to implement a neural network that predicts the stock market in python. In input I have a 2d numpy array and I want to normalize the data. I tried with this code but I don't this this is the best choice for this type of task.

def normData(data):
    #data_scaled = preprocessing.scale(data)
    data = scale( data, axis=0, with_mean=True, with_std=True, copy=True )
    return data

Do you know any other kind of normalization process that could better fit this task and its python implementation? Thank you

UPDATE: Now before the normalization I transfrom the ndarray to list, but printing

print data.mean(axis=0)

the mean is way far from 0. Its something like 4. Any ideas?

like image 552
Pino Avatar asked Jan 26 '26 17:01

Pino


1 Answers

I personally would use scikit-learn's standard scalar module. It allows you to pick the mean and standard deviation that you want and is very fast.

from sklearn.preprocessing import StandardScaler

# Load data and split into testing and training data

scale = StandardScaler(with_mean=0, with_std=1)
scale.fit(training_data, training_label)
new_training_data = scale.transform(training_data)
new_testing_data = scale.transform(testing_data)

A link to the documentation:

http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html

like image 157
Joshua Howard Avatar answered Jan 28 '26 10:01

Joshua Howard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!