Learning Vector Quantization (LVQ1) keeps a small set of labeled prototypes. For each training example, the nearest prototype wins. If the winner has the same label as the example, it moves toward the example. If the labels differ, it moves away.
Implement lvq1_step(prototypes, proto_labels, x, y, lr).
prototypes is a K by d array, proto_labels has length K, x has length d, y is the example's label, and lr >= 0 is the learning rate.x. On a tie, pick the lowest index.proto_labels[winner] == y, set p = p + lr * (x - p). Otherwise set p = p - lr * (x - p).(new_prototypes, winner_index). Do not modify the input array.prototypes must be a non-empty 2-D array. Otherwise raise ValueError.proto_labels must have length K, and x must have length d. Otherwise raise ValueError.lr < 0 raises ValueError.Compute the distances to all prototypes with broadcasting, then use argmin, which already returns the lowest index on a tie.
No results yet
Run your code to check it against the examples, or submit to run every test.