Given the line
y= 3x+ 15
, and the points a = (1,0) and b= (9,0), which point
has the smallest squared error from the line?
def sq_err(p):
x, y = p
y_actual = 3*x + 15
return (y-y_actual)**2
def main():
a = (1, 0)
b = (9, 0)
err_a = sq_err(a)
err_b = sq_err(b)
if err_a < err_b:
print(f'Point {a} has square error {err_a} from the line, and it\'s the smallest')
elif err_b < err_a:
print(f'Point {b} has square error {err_b} from the line, and it\'s the smallest')
else:
print(f'Points {a} and {b} have the same square errors {err_a} from the line')
main()
Comments
Leave a comment