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 | Mathematical Analysis
Mathematics for Data Science

bookChallenge: 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 (mm**) and intercept (bb) so that the line closely follows the data points.

The expression you are trying to minimize is:

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

The gradient descent update rules for minimizing this function 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{\partial J}{\partial m} is the partial derivative of the loss function with respect to mm;
  • Jb\frac{\partial J}{\partial b} is the partial derivative of the loss function with respect to bb.

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 mm and bb, use gradient descent.

Tarefa

Swipe to start coding

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

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 11
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

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

close

Awesome!

Completion rate improved to 1.89

bookChallenge: Fitting a Line with Gradient Descent

Deslize para mostrar o menu

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 (mm**) and intercept (bb) so that the line closely follows the data points.

The expression you are trying to minimize is:

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

The gradient descent update rules for minimizing this function 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{\partial J}{\partial m} is the partial derivative of the loss function with respect to mm;
  • Jb\frac{\partial J}{\partial b} is the partial derivative of the loss function with respect to bb.

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 mm and bb, use gradient descent.

Tarefa

Swipe to start coding

  1. Complete the Python code below to implement the gradient descent steps.
  2. Fill in the missing expressions using basic Python operations.
  3. Track how the values of 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!

close

Awesome!

Completion rate improved to 1.89
Seção 3. Capítulo 11
single

single

some-alt