Size, Rooms and Age

Machine Learning in CodeEasy+10 XP+10

Size, Rooms and Age

An estate agent has a table of flats. Each row is three numbers, and each answer in prices is the asking price.

Write price_coefficients(rows, prices, names).

  • names holds the names of the three columns, in the same order as each row.
  • Fit a LinearRegression model on all the rows.
  • Return a dict with one entry per column name, holding that column's coefficient, plus one more entry "intercept" for the intercept.
  • Round every number to 2 decimal places and use plain Python floats.

Examples

rows = [[50, 2, 10], [70, 3, 5], [40, 1, 30], [90, 4, 2], [60, 2, 20], [80, 3, 15]]
prices = [170, 250, 90, 326, 180, 260]
names = ['size', 'rooms', 'age']
returns {'size': 3.0, 'rooms': 10.0, 'age': -2.0, 'intercept': 20.0}
rows = [[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 1], [2, 1, 0]]
prices = [12, 8, 5, 20, 23]
names = ['a', 'b', 'c']
returns {'a': 8.0, 'b': 5.0, 'c': 3.0, 'intercept': 3.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