Back to Practice
#0011

One Step of Gradient Descent

MediumML20 min15 XP

Problem

Given a current weight, a gradient, and a learning rate, return the updated weight after one gradient descent step.

Why This Matters

Many ML algorithms are just repeated parameter updates. This problem makes the update rule concrete.

Function Signature

def gradient_step(weight, gradient, learning_rate):

Examples

Example 1
Inputweight = 2.0, gradient = 0.5, learning_rate = 0.1
Output1.95

Move opposite the gradient: 2.0 - 0.1*0.5 = 1.95.

Constraints

  • Inputs are numbers.
  • Learning rate is non-negative.
  • Return a number.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 4 hidden categories
Positive gradient
Input2.0, 0.5, 0.1
Expected1.95

A positive gradient decreases the weight.

Negative gradient
Input2.0, -0.5, 0.1
Expected2.05

A negative gradient increases the weight because subtracting a negative adds.

Hidden Test Categories
Zero gradientZero learning rateLarge gradientFloating point tolerance