Complete the code to import the spline interpolation function from scipy.
from scipy.interpolate import [1]
The UnivariateSpline function from scipy.interpolate is used for spline interpolation of 1D data.
Complete the code to create a spline interpolation object for given x and y data.
spline = UnivariateSpline(x, [1])The UnivariateSpline function takes the x and y data points to create the spline.
Fix the error in the code to evaluate the spline at new points.
y_new = spline([1])To evaluate the spline, pass the new x-values where you want predictions, usually stored in x_new.
Fill both blanks to create a dictionary of squared errors for points where y is greater than 0.
errors = {x: (y - spline(x))[1]2 for x, y in zip(x_vals, y_vals) if y [2] 0}The squared error is calculated using the power operator **. The condition filters points where y is greater than zero using >.
Fill all three blanks to create a dictionary of absolute errors for points where y is less than 5.
abs_errors = [1]: abs([2] - spline([1])) for [1] , [2] in zip(x_vals, y_vals) if [2] [3] 5}
The dictionary keys are the x values. The absolute error is the absolute difference between y and the spline evaluated at x. The condition filters points where y is less than 5 using <.