## 彈性、受控制且可解釋的機器學習技術 (採用以 Lattice 為基礎的模型)

```import numpy as np
import tensorflow as tf
import tensorflow_lattice as tfl

model = tf.keras.models.Sequential()
tfl.layers.ParallelCombination([
# Monotonic piece-wise linear calibration with bounded output
tfl.layers.PWLCalibration(
monotonicity='increasing',
input_keypoints=np.linspace(1., 5., num=20),
output_min=0.0,
output_max=1.0),
# Diminishing returns
tfl.layers.PWLCalibration(
monotonicity='increasing',
convexity='concave',
input_keypoints=np.linspace(0., 200., num=20),
output_min=0.0,
output_max=2.0),
# Partially monotonic categorical calibration: calib(0) <= calib(1)
tfl.layers.CategoricalCalibration(
num_buckets=4,
output_min=0.0,
output_max=1.0,
monotonicities=[(0, 1)]),
]))
tfl.layers.Lattice(
lattice_sizes=[2, 3, 2],
monotonicities=['increasing', 'increasing', 'increasing'],
# Trust: model is more responsive to input 0 if input 1 increases
edgeworth_trusts=(0, 1, 'positive')))
model.compile(...)
```

TensorFlow Lattice 程式庫可實作受到限制且以 Lattice 為基礎的可解釋模型。這個程式庫可讓你透過常識或政策導向的形狀限制，將領域知識注入學習程序。這項作業是使用一系列的 Keras 層來執行，這些 Keras 層可滿足單調性、凸性和特性互動方式等限制。這個程式庫也提供易於設定的預製模型罐頭 Estimator

TF Lattice 可讓你運用領域知識，針對訓練資料集未涵蓋的輸入空間進行更有效的推論。當提供發布與訓練發布不同時，這有助於避免發生非預期的模型行為。

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"缺少我需要的資訊" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"過於複雜/步驟過多" },{ "type": "thumb-down", "id": "outOfDate", "label":"過時" },{ "type": "thumb-down", "id": "translationIssue", "label":"翻譯問題" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"示例/程式碼問題" },{ "type": "thumb-down", "id": "otherDown", "label":"其他" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"容易理解" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"確實解決了我的問題" },{ "type": "thumb-up", "id": "otherUp", "label":"其他" }]