Fare for a Longer Ride

Machine Learning in CodeEasy+10 XP+10

Fare for a Longer Ride

A taxi company has a few past rides: the distance in kilometres (km) and the fare paid (fares). They want quick quotes for new distances, including some longer than any ride they have seen.

Write quote_fares(km, fares, new_km).

  • Fit a LinearRegression model with distance as the only feature.
  • Predict the fare for every distance in new_km, in the same order.
  • Return the predictions as a list of plain floats, each rounded to 2 decimal places.

Examples

km = [1, 3, 4, 6, 10]
fares = [4.5, 8.1, 10.2, 13.8, 22.3]
new_km = [2, 8, 16]
returns [6.24, 18.12, 33.96]
km = [2, 4, 6]
fares = [6.0, 9.0, 12.0]
new_km = [5, 20]
returns [10.5, 33.0]

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