Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Fitting a Line with Gradient Descent | Section
Python Math Module Essentials: Trigonometry, Logarithms, and Constants - 1769704232288
Секція 1. Розділ 27
single

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 (mm) and intercept (bb) using iterative updates.

You need to minimize the loss function:

1ni=1n(yi(mxi+b))2\frac{1}{n}\sum^n_{i=1}(y_i - (mx_i + b))^2

The gradient descent update rules are:

mmαJmbbαJbm \larr m - \alpha \frac{\partial J}{\partial m} \\[6 pt] b \larr b - \alpha \frac{\partial J}{\partial b}

Where:

  • α\alpha is the learning rate (step size);
  • Jm\frac{\raisebox{1pt}{$\partial J$}}{\raisebox{-1pt}{$\partial m$}} is the partial derivative of the loss function with respect to mm;
  • Jb\frac{\raisebox{1pt}{$\partial J$}}{\raisebox{-1pt}{$\partial b$}} is the partial derivative of the loss function with respect to bb.

Your task:

  1. Complete the Python code below to implement the gradient descent steps.
  2. Fill in missing expressions using basic Python operations.
  3. Track how m and b change as the algorithm runs.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 27
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt