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 | Mathematical Analysis
Mathematics for Data Science with Python
セクション 3.  11
single

single

bookChallenge: 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実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 3.  11
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt