What Is the Café Model Leaning On?

Machine Learning in CodeEasy+10 XP+10

What Is the Café Model Leaning On?

A café owner fitted a model to predict daily sales from three columns. She wants to know which column the model relies on most.

Task: write most_important(rows, sales, names).

  • rows is a list of days, each a list of feature values. sales holds each day's sales. names holds the column names, in column order.
  • Fit LinearRegression() on rows and sales.
  • Run permutation_importance(model, rows, sales, n_repeats=10, random_state=0) on the same rows.
  • Return the name of the column with the highest mean importance (importances_mean).

Examples

rows = [[17.8, 9.5, 2], [12.8, 4.2, 2], [15.2, 5.5, 2], [18.5, 3.3, 2], [12.6, 4.5, 5], [10.1, 2.6, 2], [12.0, 4.9, 2], [23.1, 5.4, 5], [9.0, 9.7, 3], [20.6, 7.8, 4], [27.9, 0.4, 4], [6.6, 6.4, 4], [19.8, 2.6, 3], [17.8, 7.5, 5], [25.5, 6.8, 5], [25.1, 1.9, 5], [26.4, 8.6, 5], [11.9, 0.1, 5], [23.0, 8.4, 5], [21.0, 8.1, 3]]
sales = [378.7, 340.7, 370.1, 414.8, 345.4, 317.5, 311.6, 467.6, 301.8, 448.1, 528.4, 258.2, 435.0, 397.0, 489.1, 512.5, 491.0, 354.7, 457.1, 420.5]
names = ['temperature', 'rain_mm', 'staff']
returns 'temperature'
rows = [[16.3, 6.0, 3], [18.0, 14.6, 5], [15.3, 5.5, 2], [15.8, 8.7, 4], [17.1, 12.7, 5], [17.0, 3.7, 5], [17.6, 17.8, 5], [19.6, 9.4, 5], [15.5, 2.1, 5], [18.4, 17.0, 2], [17.0, 10.3, 5], [17.2, 17.8, 4], [19.1, 10.0, 2], [17.6, 4.3, 4], [15.2, 14.0, 4], [19.2, 7.7, 3], [18.0, 15.3, 5], [15.9, 3.6, 3], [15.1, 16.7, 3], [17.4, 12.4, 2]]
sales = [235.1, 134.4, 263.9, 210.8, 158.8, 305.2, 80.1, 205.1, 320.5, 91.5, 190.5, 97.8, 204.0, 271.7, 137.6, 242.9, 120.3, 288.4, 79.5, 157.4]
names = ['temperature', 'rain_mm', 'staff']
returns 'rain_mm'

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