Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Fitting a Line with Gradient Descent | Section
Python Math Module Essentials: Trigonometry, Logarithms, and Constants - 1769704232288
Seção 1. Capítulo 27
single

single

Challenge: Fitting a Line with Gradient Descent

Deslize para mostrar o menu

Tarefa

Deslize para começar a programar

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.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 27
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

some-alt