神經網路

Python 金融 Machine Learning

Nathan George

Data Science Professor

GPU 摩爾定律

Python 金融 Machine Learning

神經網路的潛力

神經網路具備:

  • 非線性
  • 變數交互作用
  • 可自訂性
Python 金融 Machine Learning

基本神經網路示意圖

Python 金融 Machine Learning

含基本數學的網路圖

Python 金融 Machine Learning

神經網路數學

Python 金融 Machine Learning

活化函式神經網路示意圖

Python 金融 Machine Learning

活化函式

Python 金融 Machine Learning

損失函式

Python 金融 Machine Learning

前向傳播

Python 金融 Machine Learning

反向傳播

Python 金融 Machine Learning

keras 與 tensorflow 標誌

Python 金融 Machine Learning

用 keras 實作神經網路

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
Python 金融 Machine Learning

用 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 金融 Machine Learning

訓練模型

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

損失曲線

Python 金融 Machine Learning

檢查效能

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 金融 Machine Learning

視覺化效能

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

預測對實際

Python 金融 Machine Learning

動手做一個神經網路!

Python 金融 Machine Learning

Preparing Video For Download...