aboutsummaryrefslogtreecommitdiff
path: root/challenge-165/lubos-kolouch/python/ch-2.py
blob: 7f82af773161da4437b8c3cc700bfb44f61dd9c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np

points = [
    (333, 129),
    (39, 189),
    (140, 156),
    (292, 134),
    (393, 52),
    (160, 166),
    (362, 122),
    (13, 193),
    (341, 104),
    (320, 113),
    (109, 177),
    (203, 152),
    (343, 100),
    (225, 110),
    (23, 186),
    (282, 102),
    (284, 98),
    (205, 133),
    (297, 114),
    (292, 126),
    (339, 112),
    (327, 79),
    (253, 136),
    (61, 169),
    (128, 176),
    (346, 72),
    (316, 103),
    (124, 162),
    (65, 181),
    (159, 137),
    (212, 116),
    (337, 86),
    (215, 136),
    (153, 137),
    (390, 104),
    (100, 180),
    (76, 188),
    (77, 181),
    (69, 195),
    (92, 186),
    (275, 96),
    (250, 147),
    (34, 174),
    (213, 134),
    (186, 129),
    (189, 154),
    (361, 82),
    (363, 89),
]

x, y = zip(*points)
A = np.vstack([x, np.ones(len(x))]).T
m, c = np.linalg.lstsq(A, y, rcond=None)[0]

print(f"Line of Best Fit: y = {m}x + {c}")