Where does the datapoints in part 2 come from? First I used the points from part 1 but they are wrong. In the solution they used the following list:

datapoints = [(1, 2), (2, 0), (3, 4), (4, 4), (5, 3)]

In the tasks file they aren’t mentioned so I have no clue where they come from?

As far as I understand this data has to be given or can should I calculate it somehow?

1 Like

You are right, points are needed for the second part, the exercise says to use the same but the slope and the intercept do not give what the exercise says.

it might be these:

first set:

```
datapoints = [(1, 2), (2, 0), (3, 4), (4, 4), (5, 3)]
```

second set:

```
datapoints = [(1, 1), (3, 3), (5, 5), (-1, -1)]
```

… although I’m not sure about those.

1 Like

It’s true, but the slope and intercept are only correct if we declare the first datapoints again.

I did this in my code from part two:

```
possible_ms = [x * 0.1 for x in range(-100, 101)]
possible_bs = [x * 0.1 for x in range(-200, 201)]
datapoints = [(1, 2), (2, 0), (3, 4), (4, 4), (5, 3)]
smallest_error = float("inf")
best_m = 0
best_b = 0
for m in possible_ms:
for b in possible_bs:
error = calculate_all_error(m, b, datapoints)
if error < smallest_error:
smallest_error = error
best_m = m
best_b = b
print(best_m, best_b, smallest_error)
```

```
Output: 0.30000000000000004 1.7000000000000002 4.999999999999999
```