Reggie's Linear Regression Question on Points

For this Project:

On second prompt, it asks you to create a function to calculate the difference between a point and the linear function. Can someone explain the syntax/logic for the point input from the function and how within the function point is then designated as x_point, y_point?

def calculate_error(m, b, point):
x_point, y_point = point
y = m*x_point + b
distance = abs(y - y_point)
return distance

1 Like

Are you asking what type it is?


Given you’ve got an x_point and a y_point, I am presuming you’re working with 2-dimensional Cartesian co-ordinates.

Hence, your point will be an (x,y) co-ordinate one assumes.

By passing in a tuple, when we do x_point, y_point = point the tuple is expanded out so that the first item of the tuple goes to the first declared variable, and the second item to the second variable. Like so:

>>> point = (2,4)
>>> x_point, y_point = point
>>> x_point
>>> y_point

Edit: I’m not a Pro user, and have no access to that course material, so this is a bit of a guess.

1 Like

Not being familiar with what data type ‘point’ might be, I guessed that it was a list or tuple. So I accessed the values like you would access a list:

x_point = point[0]
y_point = point[1]

It’s not as elegant as the one line of code solution, but I thought it might help you visualize what is going on better anyway.