[Solved] Python finding best fit line


I’m not sure what you’re trying to do because I don’t understand your question that well.

Unfortunately, the code runs insanely slow. (It takes about 75 minutes to complete.) Mabey you should look for a different solution.
I copied it out for the image and got:

x = [1.0, 2.0, 3.0]
y = [1.0, 3.0, 4.0]
a = 0
b = 0
c = 0
sumD = 10

for n in range(1000):
    testA = -5.0 + n / 1000
    for k in range(1000):
        testB = -5.0 + k / 1000
        for z in range(1000):
            testC = -5.0 + z / 1000
            testSum = (testA*x[0]**2+testB*x[0]+testC-y[0])**2+(testA*x[1]**2+testB*x[1]+testC-y[1])**2+(testA*x[2]**2+testB*x[2]+testC-y[2])**2
            if testSum < sumD:
                a = testA
                b = testB
                c = testC

print(a) #This is the correct syntax to use
print(b)
print(c)

7

solved Python finding best fit line