Fuel at Top Speed

Machine Learning in CodeEasy+10 XP+10

Fuel at Top Speed

A car's fuel use does not rise in a straight line with speed. It climbs faster and faster. You have a few measurements of speed (speeds) and fuel use (fuel).

Write curve_predict(speeds, fuel, degree, new_speeds).

  • Build a pipeline with make_pipeline(PolynomialFeatures(degree), LinearRegression()).
  • Fit it with speed as the only feature.
  • Predict the fuel use for every speed in new_speeds, in order.
  • Return the predictions as a list of plain floats, each rounded to 2 decimal places.

Examples

speeds = [30, 50, 70, 90, 110]
fuel = [4.8, 5.0, 6.8, 10.2, 15.2]
degree = 2
new_speeds = [60, 120]
returns [5.7, 18.3]
speeds = [30, 50, 70, 90, 110]
fuel = [4.8, 5.0, 6.8, 10.2, 15.2]
degree = 1
new_speeds = [60, 120]
returns [7.1, 14.9]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run