Neural Networks

Machine Learning para finanzas con Python

Nathan George

Data Science Professor

GPU moore's law

Machine Learning para finanzas con Python

Neural networks have potential

Neural nets have:

  • non-linearity
  • variable interactions
  • customizability
Machine Learning para finanzas con Python

basic neural net diagram

Machine Learning para finanzas con Python

net diagram with basic math

Machine Learning para finanzas con Python

neural net math

Machine Learning para finanzas con Python

activation neural net diagram

Machine Learning para finanzas con Python

activation function

Machine Learning para finanzas con Python

loss function

Machine Learning para finanzas con Python

forward pass

Machine Learning para finanzas con Python

backwards pass

Machine Learning para finanzas con Python

keras and tensorflow logos

Machine Learning para finanzas con Python

Implementing a neural net with keras

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
Machine Learning para finanzas con Python

Implementing a neural net with keras

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense


model = Sequential()
model.add(Dense(50, input_dim=scaled_train_features.shape[1], activation='relu')) model.add(Dense(10, activation='relu')) model.add(Dense(1, activation='linear'))
Machine Learning para finanzas con Python

Fitting the model

model.compile(optimizer='adam', loss='mse')
history = model.fit(scaled_train_features, 
                    train_targets, 
                    epochs=50)
Machine Learning para finanzas con Python
plt.plot(history.history['loss'])
plt.title('loss:' + str(round(history.history['loss'][-1], 6)))
plt.xlabel('epoch')
plt.ylabel('loss')
plt.show()

loss plot

Machine Learning para finanzas con Python

Checking out performance

from sklearn.metrics import r2_score

# calculate R^2 score
train_preds = model.predict(scaled_train_features)
print(r2_score(train_targets, train_preds))
0.4771387560719418
Machine Learning para finanzas con Python

Plot performance

# plot predictions vs actual
plt.scatter(train_preds, train_targets)
plt.xlabel('predictions')
plt.ylabel('actual')
plt.show()

preds vs actual

Machine Learning para finanzas con Python

Make a neural net!

Machine Learning para finanzas con Python

Preparing Video For Download...