Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende 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.

Tarea

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.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 11
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

close

Awesome!

Completion rate improved to 1.89

bookChallenge: Fitting a Line with Gradient Descent

Desliza para mostrar el menú

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.

Tarea

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.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

close

Awesome!

Completion rate improved to 1.89
Sección 3. Capítulo 11
single

single

some-alt