First off, I'm new to Python and Machine learning, but I want to dive into it head first with a practical example (one which I'm sure many will have attempted before me).
I have a dataset with 300+ stocks, 4 value metrics for each stock (recorded 3 years ago) and the stock price increase over the last 3 years.
My goal? Creating a ML model that estimates 3-year stock return based on fundamental/value metrics (ex. Price/Book, Price/Equity, FCF growth etc.).
The dataset looks like this: https://i.stack.imgur.com/WBC2K.png
My challenges?
I'm doing something wrong during the training of the model, because I get this as output during training:
Epoch 1/100
8/8 [==============================] - 1s 3ms/step - loss: nan - accuracy: 0.0000e+00
Epoch 2/100
8/8 [==============================] - 0s 3ms/step - loss: nan - accuracy: 0.0000e+00
Epoch 3/100
When trying to predict a value
X_predict = [[1.43, 0.73, 0.37, -0.92]]
print(seann.predict(sc.transform(X_predict)))
I get output:
1/1 [==============================] - 0s 63ms/step
[[nan]]
I think my error lies in the following:
- Standardising the input data
from sklearn import preprocessing
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
- Finding the right parameters to initialise the model
seann = tf.keras.models.Sequential()
seann.add(tf.keras.layers.Dense(units=4, activation='relu'))
seann.add(tf.keras.layers.Dense(units=4, activation='relu'))
seann.add(tf.keras.layers.Dense(units=1, activation='linear'))
seann.compile(optimizer = 'adam' , loss = 'mean_squared_error', metrics = ['accuracy'])