Milestone 5 of 8
Predict every query without losing identity
Produce one source-ordered result per query and prove that IDs, neighbors, votes, and expected labels stay aligned.
Apply the single-query path to the whole query table without turning a batch loop into an identity problem.
Goal
Produce one prediction record per query in source order and prove that no query is omitted, duplicated, or paired with another query's neighbor trace.
Inputs
Use all validated query records, the reference records, valid k, the distance
function, ordered-neighbor function, and deterministic label-selection
function. Each query retains query_id, source row position, coordinates, and
expected label for checking only.
Deliverables
Implement batch orchestration in src/main.py or a clearly separated function
that produces output/predictions.csv, output/neighbor_traces.json, and
output/vote_traces.json.
Each prediction row includes query ID, expected label, predicted label, match status, and source position. Each trace names the same query ID and preserves its ordered neighbors and vote evidence. Keep prediction records in query source order even though each query's neighbors are sorted independently.
Checks
Check that the output count equals the query count, every query ID appears exactly once, source positions are unique and ordered, and every prediction trace and vote trace points to the same query. Reconstruct one row from its neighbor and vote traces.
Use a fixture with repeated labels and at least two queries whose nearest rows are different. Check that one query's neighbors are not reused for another query and that input tables remain unchanged.
Workspace
Keep orchestration in src/main.py; reuse src/neighbors.py and
src/predict.py for each query. Write the three result artifacts under
output/ and preserve the source order from data/query_records.csv.
Hints
HintCarry the query ID through every call
HintSource order and neighbor order differ
Review
Choose two query rows and follow each identity through its prediction, neighbor trace, vote trace, and CSV row. Explain why preserving expected labels is useful for a bounded check but does not change the prediction rule.
How to check your work
Checks compare the batch record shape, identity fields, and trace links with the supplied fixture. The supplied fixture does not hide the per-query evidence behind only an aggregate count.