Redes neurais

Machine Learning para Finanças em Python

Nathan George

Data Science Professor

Lei de Moore das GPUs

Machine Learning para Finanças em Python

Redes neurais têm potencial

Redes neurais têm:

  • não linearidade
  • interações entre variáveis
  • alta personalização
Machine Learning para Finanças em Python

diagrama básico de rede neural

Machine Learning para Finanças em Python

diagrama com matemática básica

Machine Learning para Finanças em Python

matemática de rede neural

Machine Learning para Finanças em Python

ativações em rede neural

Machine Learning para Finanças em Python

função de ativação

Machine Learning para Finanças em Python

função de perda

Machine Learning para Finanças em Python

passagem para frente

Machine Learning para Finanças em Python

passagem para trás

Machine Learning para Finanças em Python

logos do keras e tensorflow

Machine Learning para Finanças em Python

Implementando uma rede neural com Keras

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
Machine Learning para Finanças em Python

Implementando uma rede neural com 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 Finanças em Python

Ajustando o modelo

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

gráfico da perda

Machine Learning para Finanças em Python

Conferindo o desempenho

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 Finanças em Python

Plotar desempenho

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

predições vs reais

Machine Learning para Finanças em Python

Crie uma rede neural!

Machine Learning para Finanças em Python

Preparing Video For Download...