Ship evaluated T-24h delay prediction model - #4
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5211088c1b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| from app.models import ModelPrediction, ScheduledFlight | ||
|
|
||
|
|
||
| MODEL_PATH = Path(__file__).resolve().parent.parent / "artifacts" / "models" / "delay-logistic-v1.json" |
There was a problem hiding this comment.
Package the model artifact with the API
In every Docker/Compose deployment, this resolves to /app/artifacts/models/delay-logistic-v1.json, but the checked Dockerfile:8-10 copies only requirements.txt and app/. Consequently both new model routes raise FileNotFoundError and return 500 responses when first invoked, even though /health remains successful; copy the artifact into the image or package it as application data.
Useful? React with 👍 / 👎.
| route_counts = prepared.groupby("route")["route"].transform("size") | ||
| prepared["route_volume_band"] = pd.qcut( | ||
| route_counts.rank(method="first"), 3, labels=["low", "medium", "high"] | ||
| ).astype(str) |
There was a problem hiding this comment.
Assign one volume band per route
When multiple routes have the same volume, rank(method="first") breaks those ties per row before binning, so flights belonging to a single route can be assigned to different low, medium, and high bands depending on row order. The committed route-volume error slices therefore do not measure coherent route-volume cohorts; derive the quantile mapping from unique routes and then map each route back to its flights.
Useful? React with 👍 / 👎.
| ("impute", SimpleImputer(strategy="most_frequent")), | ||
| ("encode", OneHotEncoder(handle_unknown="ignore")), | ||
| ] |
There was a problem hiding this comment.
Preserve an explicit category for unseen codes
For any carrier or airport absent from the training sample, handle_unknown="ignore" produces an all-zero categorical vector, and portable inference mirrors that behavior with a zero coefficient. This is reachable even with schema-valid input because the endpoint accepts four-letter airport codes while every airport in the artifact is three letters, and it violates the accepted unknown-category behavior in docs/ml/data-contract.md:88-93; bucket unknown values explicitly during both training and inference.
Useful? React with 👍 / 👎.
What changed
Why
The original rules score was transparent but not trained or evaluated. This milestone adds honest applied-ML evidence without mixing post-departure leakage fields into a T-24h prediction.
Validation