Challenge: Fitting a Line with Gradient Descent
A student is exploring how to use gradient descent to fit a straight line to a small dataset. The dataset shows years of experience versus salary (in thousands), and the goal is to find the best-fitting line using an iterative update rule.
Your task is to adjust the slope (m**) and intercept (b) so that the line closely follows the data points.
The expression you are trying to minimize is:
n1i=1∑n(yi−(mxi+b))2The gradient descent update rules for minimizing this function are:
m←m−α∂m∂Jb←b−α∂b∂JWhere:
- α is the learning rate (step size);
- ∂m∂J is the partial derivative of the loss function with respect to m;
- ∂b∂J is the partial derivative of the loss function with respect to b.
This loss measures how far off your predicted points are from the actual data. (P.S. Smaller values mean the line fits the data better.)
In order to find values m and b, use gradient descent.
Swipe to start coding
- Complete the Python code below to implement the gradient descent steps.
- Fill in the missing expressions using basic Python operations.
- Track how the values of
m
andb
change as the algorithm runs.
Рішення
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
What are the formulas for the partial derivatives with respect to m and b?
Can you explain how to choose a good learning rate (α)?
Can you walk me through an example of one iteration of gradient descent for this problem?
Awesome!
Completion rate improved to 1.89
Challenge: Fitting a Line with Gradient Descent
Свайпніть щоб показати меню
A student is exploring how to use gradient descent to fit a straight line to a small dataset. The dataset shows years of experience versus salary (in thousands), and the goal is to find the best-fitting line using an iterative update rule.
Your task is to adjust the slope (m**) and intercept (b) so that the line closely follows the data points.
The expression you are trying to minimize is:
n1i=1∑n(yi−(mxi+b))2The gradient descent update rules for minimizing this function are:
m←m−α∂m∂Jb←b−α∂b∂JWhere:
- α is the learning rate (step size);
- ∂m∂J is the partial derivative of the loss function with respect to m;
- ∂b∂J is the partial derivative of the loss function with respect to b.
This loss measures how far off your predicted points are from the actual data. (P.S. Smaller values mean the line fits the data better.)
In order to find values m and b, use gradient descent.
Swipe to start coding
- Complete the Python code below to implement the gradient descent steps.
- Fill in the missing expressions using basic Python operations.
- Track how the values of
m
andb
change as the algorithm runs.
Рішення
Дякуємо за ваш відгук!
Awesome!
Completion rate improved to 1.89single