Fit a one-dimensional function with a fixed ReLU-hinge basis. Build the basis matrix Bij=max(xi−tj,0) for the given knots tj, solve the least-squares problem for the weights, and return both the fitted values and the weights.
Implement solve(X, y, knots).
Returns. Return a tuple (fitted, weights): the fitted values Bw (length n) and the weights (length = number of knots). Rank-deficient bases use the minimum-norm least-squares solution (np.linalg.lstsq).
Example 1
Input:
solve([0, 1, 2], [0, 1, 2], [0])
Output:
([0.0, 1.0, 2.0], [1.0])
Example 2
Input:
solve([0, 1, 2], [0, 0, 1], [0])
Output:
([0.0, 0.4, 0.8], [0.4])
No results yet
Run your code to check it against the examples, or submit to run every test.