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 7 |
+
- keras
|
| 8 |
+
- tabular
|
| 9 |
+
- classification
|
| 10 |
+
- ensemble
|
| 11 |
+
- transportation
|
| 12 |
+
model-index:
|
| 13 |
+
- name: imt-ml-track-ensemble-20250906-124755
|
| 14 |
+
results:
|
| 15 |
+
- task:
|
| 16 |
+
type: tabular-classification
|
| 17 |
+
name: Track classification
|
| 18 |
+
dataset:
|
| 19 |
+
name: MBTA Track Assignment (custom)
|
| 20 |
+
type: custom
|
| 21 |
+
split: validation
|
| 22 |
+
metrics:
|
| 23 |
+
- type: accuracy
|
| 24 |
+
name: Average individual accuracy
|
| 25 |
+
value: 0.5957
|
| 26 |
+
- type: accuracy
|
| 27 |
+
name: Best individual accuracy
|
| 28 |
+
value: 0.6049
|
| 29 |
+
- type: loss
|
| 30 |
+
name: Average individual loss
|
| 31 |
+
value: 1.2251
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
# imt-ml Track Prediction — Ensemble (2025-09-06 12:47:55)
|
| 35 |
+
|
| 36 |
+
Predicts which MBTA commuter rail track/platform a train will use, using a small tabular neural-network ensemble trained on historical assignments. This card documents the artifacts in `output/ensemble_20250906_124755`.
|
| 37 |
+
|
| 38 |
+
## Model Summary
|
| 39 |
+
|
| 40 |
+
- Task: Tabular multi-class classification (13 track classes)
|
| 41 |
+
- Library: Keras (TensorFlow backend)
|
| 42 |
+
- Architecture: 6-model ensemble (diverse dense nets with embeddings + cyclical time features); softmax outputs averaged at inference
|
| 43 |
+
- Inputs (preprocessed):
|
| 44 |
+
- Categorical: `station_id` (int index), `route_id` (int index), `direction_id` (0/1)
|
| 45 |
+
- Time (cyclical): `hour_sin`, `hour_cos`, `minute_sin`, `minute_cos`, `day_sin`, `day_cos`
|
| 46 |
+
- Continuous: `scheduled_timestamp` (float seconds since epoch; normalized in-model)
|
| 47 |
+
- Outputs: Probability over 13 track labels (softmax)
|
| 48 |
+
- License: MIT
|
| 49 |
+
|
| 50 |
+
## Files in This Repo
|
| 51 |
+
|
| 52 |
+
- `track_prediction_ensemble_model_0_final.keras` … `track_prediction_ensemble_model_5_final.keras` — individual ensemble members
|
| 53 |
+
- `track_prediction_ensemble_model_*_best.keras` — best checkpoints during training (may match `final`)
|
| 54 |
+
- `training_report.md` — training configuration and metrics
|
| 55 |
+
|
| 56 |
+
Note: Ensemble training currently does not emit a `*_vocab.json`. See “Preprocessing & Vocab” below.
|
| 57 |
+
|
| 58 |
+
## Preprocessing & Vocab
|
| 59 |
+
|
| 60 |
+
Models expect integer indices for `station_id` and `route_id`, and raw `direction_id` 0/1. In training, indices are produced by lookup tables built from the dataset vocabularies. To reproduce inference exactly, you must use the same vocabularies (station/route/track) that were present at training time or ensure consistent mapping.
|
| 61 |
+
|
| 62 |
+
What to use:
|
| 63 |
+
- The training pipeline’s dataset loader (`imt_ml.dataset.create_feature_engineering_fn`) defines the exact feature mapping. If you need the vocab files, re-run a training or export step to generate them for your data snapshot, or save the vocab mapping alongside the model.
|
| 64 |
+
|
| 65 |
+
## Metrics (validation)
|
| 66 |
+
|
| 67 |
+
From `training_report.md`:
|
| 68 |
+
- Average validation loss: 1.2251
|
| 69 |
+
- Average validation accuracy: 0.5957
|
| 70 |
+
- Best individual accuracy: 0.6049
|
| 71 |
+
- Worst individual accuracy: 0.5812
|
| 72 |
+
- Ensemble accuracy stdev: 0.0087
|
| 73 |
+
- Dataset size: 24,832 records (310 train steps/epoch, 77 val steps/epoch)
|
| 74 |
+
|
| 75 |
+
These metrics reflect individual model performance; at inference time, average the softmax probabilities across all 6 models to produce ensemble predictions.
|
| 76 |
+
|
| 77 |
+
## Example Usage (local Python)
|
| 78 |
+
|
| 79 |
+
This snippet loads all six Keras models and averages their softmax outputs. Replace the feature values with your preprocessed tensors/arrays, ensuring they match the training feature schema and index mappings.
|
| 80 |
+
|
| 81 |
+
```python
|
| 82 |
+
import numpy as np
|
| 83 |
+
import keras
|
| 84 |
+
|
| 85 |
+
# Load ensemble members
|
| 86 |
+
paths = [
|
| 87 |
+
"track_prediction_ensemble_model_0_final.keras",
|
| 88 |
+
"track_prediction_ensemble_model_1_final.keras",
|
| 89 |
+
"track_prediction_ensemble_model_2_final.keras",
|
| 90 |
+
"track_prediction_ensemble_model_3_final.keras",
|
| 91 |
+
"track_prediction_ensemble_model_4_final.keras",
|
| 92 |
+
"track_prediction_ensemble_model_5_final.keras",
|
| 93 |
+
]
|
| 94 |
+
models = [keras.models.load_model(p, compile=False) for p in paths]
|
| 95 |
+
|
| 96 |
+
# Prepare one example (batch size 1) — values shown are placeholders.
|
| 97 |
+
# You must convert raw strings to indices using the same vocab mapping used in training.
|
| 98 |
+
features = {
|
| 99 |
+
"station_id": np.array([12], dtype=np.int64), # int index
|
| 100 |
+
"route_id": np.array([3], dtype=np.int64), # int index
|
| 101 |
+
"direction_id": np.array([1], dtype=np.int64), # 0 or 1
|
| 102 |
+
"hour_sin": np.array([0.707], dtype=np.float32),
|
| 103 |
+
"hour_cos": np.array([0.707], dtype=np.float32),
|
| 104 |
+
"minute_sin": np.array([0.0], dtype=np.float32),
|
| 105 |
+
"minute_cos": np.array([1.0], dtype=np.float32),
|
| 106 |
+
"day_sin": np.array([0.433], dtype=np.float32),
|
| 107 |
+
"day_cos": np.array([0.901], dtype=np.float32),
|
| 108 |
+
"scheduled_timestamp": np.array([1.7260e9], dtype=np.float32),
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
# Predict per model and average probabilities
|
| 112 |
+
probs = [m.predict(features, verbose=0) for m in models]
|
| 113 |
+
avg_prob = np.mean(probs, axis=0) # shape: (batch, num_tracks)
|
| 114 |
+
pred_class = int(np.argmax(avg_prob, axis=-1)[0])
|
| 115 |
+
print({"predicted_track_index": pred_class, "probabilities": avg_prob[0].tolist()})
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
Tip: If you have the track vocabulary used at training time, you can map `pred_class` back to its track label string by indexing into that `track_vocab` list.
|
| 119 |
+
|
| 120 |
+
## Training Data
|
| 121 |
+
|
| 122 |
+
- Source: Historical MBTA track assignments exported from Redis to TFRecord
|
| 123 |
+
- Features:
|
| 124 |
+
- Categorical: `station_id`, `route_id`, `direction_id`
|
| 125 |
+
- Temporal: hour, minute, day_of_week (encoded as sin/cos pairs)
|
| 126 |
+
- Target: `track_number` (13 classes)
|
| 127 |
+
|
| 128 |
+
## Training Procedure
|
| 129 |
+
|
| 130 |
+
- Command: `ensemble`
|
| 131 |
+
- Num models: 6 (architectural diversity: deep, wide, standard)
|
| 132 |
+
- Epochs: 150
|
| 133 |
+
- Batch size: 64
|
| 134 |
+
- Base learning rate: 0.001 (varied 0.8x–1.2x per model)
|
| 135 |
+
- Regularization: L1/L2, Dropout, BatchNorm; cosine LR scheduling and early stopping when enabled
|
| 136 |
+
|
| 137 |
+
## Intended Use & Limitations
|
| 138 |
+
|
| 139 |
+
- Intended for assisting real-time track/platform assignment predictions for MBTA commuter rail.
|
| 140 |
+
- Not a safety system; always defer to official dispatch/operations.
|
| 141 |
+
- Sensitive to concept drift (schedule/operational changes) and to unseen stations/routes.
|
| 142 |
+
- Requires consistent categorical index mapping between training and inference.
|
| 143 |
+
|