PY-86
Evaluate Every Parameter Candidate
Task
Write evaluate_parameter_candidates(inputs, targets, candidates).
inputs and targets are finite one-dimensional numeric NumPy arrays with
the same non-zero length. candidates is a non-empty one-dimensional array of
finite numeric candidate slopes. The arrays are observations in their existing
order; do not reorder them. The supplied model has a fixed zero intercept.
For each candidate slope p, use the supplied complete rules:
prediction = p * input
error = prediction - target
score = mean(error ** 2)
Evaluate every candidate and retain the complete table. Return a dictionary with exactly these keys:
"candidates": an independentfloat64copy in the supplied order;"predictions": an independentfloat64array of shape(number_of_candidates, number_of_observations);"scores": an independentfloat64array with one mean-squared-error score per candidate;"best_index": the zero-based index of the smallest score;"best_candidate": the candidate at that index as afloat;"best_score": its score as afloat.
If two scores are exactly equal, choose the first candidate in the supplied
order. This is the only tie rule; do not use a tolerance to change it. Raise
ValueError("inputs and targets must be non-empty and have equal length")
for an empty or unequal observation pair and
ValueError("candidates must be non-empty") for no candidates. Keep every
input unchanged.
Example
For inputs=[0,1,2], targets=[0,2,4], and candidates=[1,2], candidate 2
predicts [0,2,4] and has score 0; candidate 1 predicts [0,1,2] and
has score 5/3. The complete prediction table has shape (2,3) and the best
index is 1.
Your implementation
You may import NumPy as np. Do not modify an input, print, or ask for input.