Секція 1. Розділ 27
single
Challenge: Fitting a Line with Gradient Descent
Свайпніть щоб показати меню
Завдання
Проведіть, щоб почати кодувати
A student wants to use gradient descent to fit a straight line to a dataset showing years of experience versus salary (in thousands). The goal is to find the best-fitting line by adjusting the slope (m) and intercept (b) using iterative updates.
You need to minimize the loss function:
n1i=1∑n(yi−(mxi+b))2The gradient descent update rules 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.
Your task:
- Complete the Python code below to implement the gradient descent steps.
- Fill in missing expressions using basic Python operations.
- Track how
mandbchange as the algorithm runs.
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 27
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат