FAQ: Linear Regression - Put it Together

This community-built FAQ covers the “Put it Together” exercise from the lesson “Linear Regression”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Science

Machine Learning

FAQs on the exercise Put it Together

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hi guys,
There is something I haven’t understood about the exercise: in the step_gradient function, the next guesses are defined by b=b_current - 0.01*b_gradient. As far as I know, the gradient is a slope, so how does an x-axis value minus a slope produce another x-axis value? Thanks for your reply!

2 Likes

In Step 4 of this lesson, the step_gradient function is called like this:

b, m = step_gradient(months, revenue, b, m)

Why is that?

Generally, gradient represents the direction in which the function increases fastest. By adding to (b, m) a vector in the direction opposite to the gradient, we can expect that the function (loss) will be smaller. (However, if the step is too large, it may go past the point of minimizing the loss, so it is adjusted by the learning rate.)

1 Like

In Python, we can assign values to multiple variables by separating variables with commas.

a, b = 1, 2

print(a)  # 1
print(b)  # 2

In Step 3, the return value of the function step_gradient() is set as a pair (tuple or list), so it’s components are assigned to b and m in one line.