神经网络

Python 金融机器学习

Nathan George

Data Science Professor

GPU 摩尔定律

Python 金融机器学习

神经网络的潜力

神经网络具备:

  • 非线性
  • 变量交互
  • 可定制性
Python 金融机器学习

基础神经网络示意图

Python 金融机器学习

含基础数学的网络图

Python 金融机器学习

神经网络数学

Python 金融机器学习

激活 神经网络示意图

Python 金融机器学习

激活函数

Python 金融机器学习

损失函数

Python 金融机器学习

前向传播

Python 金融机器学习

反向传播

Python 金融机器学习

keras 与 tensorflow 标志

Python 金融机器学习

用 Keras 实现神经网络

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
Python 金融机器学习

用 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'))
Python 金融机器学习

拟合模型

model.compile(optimizer='adam', loss='mse')
history = model.fit(scaled_train_features, 
                    train_targets, 
                    epochs=50)
Python 金融机器学习
plt.plot(history.history['loss'])
plt.title('loss:' + str(round(history.history['loss'][-1], 6)))
plt.xlabel('epoch')
plt.ylabel('loss')
plt.show()

损失曲线

Python 金融机器学习

评估性能

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
Python 金融机器学习

可视化性能

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

预测 vs 实际

Python 金融机器学习

构建一个神经网络!

Python 金融机器学习

Preparing Video For Download...