Sunshine and Ice Cream

Machine Learning in CodeEasy+10 XP+10

Sunshine and Ice Cream

An ice-cream van wrote down the hours of sunshine each day (hours) and the number of cones it sold (cones).

Write fit_line(hours, cones).

  • Fit a LinearRegression model with the hours as the only feature. Remember that fit wants X shaped like a table: one row per day, one column.
  • Return [slope, intercept]: the model's coef_ for the hours, then its intercept_.
  • Round both to 2 decimal places and return plain Python floats.

Examples

hours = [2, 4, 5, 7, 9]
cones = [30, 52, 61, 80, 101]
returns [10.01, 10.73]
hours = [1, 2, 3, 4]
cones = [10, 20, 30, 40]
returns [10.0, 0.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