Nhập môn TensorFlow bằng Python
Isaiah Hull
Visiting Associate Professor of Finance, BI Norwegian Business School


import numpy as np
import tensorflow as tf
# Định nghĩa đặc trưng người vay ví dụ
young, old = 0.3, 0.6
low_bill, high_bill = 0.1, 0.5
# Áp dụng bước nhân ma trận cho mọi kết hợp đặc trưng
young_high = 1.0*young + 2.0*high_bill
young_low = 1.0*young + 2.0*low_bill
old_high = 1.0*old + 2.0*high_bill
old_low = 1.0*old + 2.0*low_bill
# Chênh lệch dự đoán vỡ nợ cho nhóm trẻ
print(young_high - young_low)
# Chênh lệch dự đoán vỡ nợ cho nhóm lớn tuổi
print(old_high - old_low)
0.8
0.8
# Chênh lệch dự đoán vỡ nợ cho nhóm trẻ
print(tf.keras.activations.sigmoid(young_high).numpy() -
tf.keras.activations.sigmoid(young_low).numpy())
# Chênh lệch dự đoán vỡ nợ cho nhóm lớn tuổi
print(tf.keras.activations.sigmoid(old_high).numpy() -
tf.keras.activations.sigmoid(old_low).numpy())
0.16337568
0.14204389
tf.keras.activations.sigmoid()sigmoid
tf.keras.activations.relu()relu
tf.keras.activations.softmax()softmaximport tensorflow as tf
# Định nghĩa lớp đầu vào
inputs = tf.constant(borrower_features, tf.float32)
# Định nghĩa lớp dense 1
dense1 = tf.keras.layers.Dense(16, activation='relu')(inputs)
# Định nghĩa lớp dense 2
dense2 = tf.keras.layers.Dense(8, activation='sigmoid')(dense1)
# Định nghĩa lớp đầu ra
outputs = tf.keras.layers.Dense(4, activation='softmax')(dense2)
Nhập môn TensorFlow bằng Python