bugger.
All challenges/Pythoneasyllm-knn-classifier-v1
THE INVESTIGATION

k-nearest-neighbor classification

Implement deterministic nearest-neighbor classification.

LLM ArchitectureML foundations

What’s going wrong

Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.

Input features and labels contain training examples, query is one vector with the same dimension, and 1 ≤ k ≤ training size. Rank squared Euclidean distances ascending, breaking ties by original row index. Return neighbors (row IDs) and label (most votes, breaking vote ties by the lexicographically smallest string label).

Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.

Expected behavior

Implement deterministic nearest-neighbor classification.

Reproduction

01 Closest row appears at the end
{"features":[[10],[3],[1]],"labels":["A","B","C"],"query":[0],"k":1}
{"neighbors":[2],"label":"C"}
02 One training point
{"features":[[1]],"labels":["a"],"query":[5],"k":1}
{"neighbors":[0],"label":"a"}
03 Tied distance selects earlier row
{"features":[[-1],[1]],"labels":["z","a"],"query":[0],"k":1}
{"neighbors":[0],"label":"z"}

Before you begin

  • Python functions, lists and dictionaries

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.