Shuffle the Twins Together

Machine Learning in CodeHard+10 XP+10

Shuffle the Twins Together

An office predicts hourly energy use from [outdoor_temp, feels_like_temp, hour]. The two temperatures are near copies of each other. Shuffle one, and the model still reads temperature from the other, so each one looks unimportant on its own.

The fix is to shuffle the twins together, with the same reordering. To keep everyone's answer the same, the reordering is handed to you.

Task: write twin_drops(rows, energy, order).

  • Fit LinearRegression() on rows and energy. Use model.score (R²) on these same rows as the baseline.
  • order is a list of row indices. Shuffling a column with it means row i gets the value that was in row order[i].
  • Measure three drops, each baseline - score_after_shuffle, each starting from the original rows:
    1. shuffle column 0 only
    2. shuffle column 1 only
    3. shuffle columns 0 and 1 together, with the same order
  • Return the three drops as plain floats, each rounded to 3 decimal places, in that order.

Examples

rows = [[24.2, 20.8, 11.9], [1.6, 1.9, 9.4], [1.5, 5.5, 15.0], [13.0, 17.0, 20.6], [11.8, 8.9, 15.6], [16.7, 18.1, 20.2], [20.4, 22.5, 5.2], [26.2, 25.7, 16.3], [15.1, 14.3, 4.7], [24.2, 20.8, 3.4], [13.5, 15.2, 5.4], [24.0, 24.1, 11.6], [0.4, -0.2, 2.0], [11.0, 8.3, 9.2], [16.7, 18.1, 17.1], [20.5, 22.6, 5.1]]
energy = [136.9, 66.2, 78.1, 119.2, 102.3, 130.1, 121.1, 152.3, 99.6, 118.2, 102.3, 131.6, 48.6, 89.4, 130.3, 122.1]
order = [3, 13, 7, 8, 0, 1, 9, 2, 6, 10, 5, 4, 12, 15, 11, 14]
returns [0.513, 0.322, 1.653]
rows = [[16.1, 20.6, 8.5], [20.2, 23.6, 15.6], [1.6, 2.9, 0.2], [24.8, 25.8, 1.1], [25.5, 30.0, 14.4], [5.6, 3.5, 17.5], [3.2, -1.1, 3.2], [17.6, 18.6, 9.6], [13.6, 13.2, 22.3], [26.8, 25.1, 7.2], [2.0, 7.0, 19.0], [1.8, 6.2, 17.8], [0.2, -3.5, 18.4], [4.5, 4.5, 19.4], [8.2, 9.8, 9.6], [26.1, 26.3, 15.0]]
energy = [117.3, 145.2, 52.7, 132.6, 160.4, 91.0, 54.5, 119.6, 121.7, 138.9, 91.5, 91.5, 76.7, 86.4, 92.6, 156.9]
order = [3, 8, 14, 12, 10, 2, 11, 1, 9, 13, 7, 5, 4, 0, 15, 6]
returns [0.577, 0.787, 2.633]

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