VOOZH about

URL: https://www.geeksforgeeks.org/data-science/partial-derivatives-in-machine-learning/

⇱ Partial derivatives in Machine Learning - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Partial derivatives in Machine Learning

Last Updated : 19 Nov, 2025

In machine learning, models have many parameters like weights and biases. The loss function shows how far predictions are from the correct output. To improve the model, we need to know how each parameter affects the loss. Partial derivatives help us update each parameter individually, which is the core idea behind gradient descent. By measuring how the loss changes with respect to each parameter, we adjust them to reduce error.

  • Partial Derivatives: A function of many variables is said to have a partial derivative if it is only related to one of the variables, holding the rest constant. For a function the partial derivative with respect to xi is denoted as .
  • Gradient: A function's gradient is a vector that, at a given moment in time, indicates the direction of the function's maximum rate of growth. When optimizing a cost function in machine learning, the gradient often indicates the direction of the sharpest rise or decline.
  • Gradient Descent: It is an optimization process that moves repeatedly in the direction of the steepest descent, which is indicated by the gradient's negative, in order to minimize a function.

To understand machine learning partial derivatives, let us examine a basic linear regression model:

Where w is the weight, b is the bias and x is the input variable.

Partial Derivatives: In order to optimise the model, we must calculate the partial derivatives of the cost function J(w,b) with respect to the parameters w and b.

,where (xi, yi) denotes the input-output pairings and m is the number of training samples.

Gradient Descent Update Rule: We use the gradient descent technique repeatedly to update the parameters:

Where:

  • w and b are the model parameters (weight and bias).
  •  is the learning rate, which controls how big each step is during optimization.
  •  and are the partial derivatives of the cost (loss) function  with respect to w and b. These tell us how much the loss changes when we tweak each parameter a little bit, all else being equal.

Implementation Of Partial derivatives in Machine Learning

  • Initialization: Initialize the weight parameter w and bias parameter b to 0 and set the learning rate α and number of epochs.
  • Prediction: Compute the model's predictions for house prices using the current values of w and b.
  • Gradient Calculation: Compute the gradients of the mean squared error cost function with respect to w and b using partial differentiation.
  • Parameter Update: Update the parameters w and b using the computed gradients and the learning rate α.
  • Iteration: Repeat the prediction, gradient calculation and parameter update steps for a specified number of epochs to optimize the parameters for the linear model.

Output:

Optimal parameters:
 w = 93.98340961256555 
 b = 21.720572459273797

Partial Derivative Examples

Example: Find the partial derivatives of the function: f(x,y) = x2y +3xy2

Solution:

1. Partial derivative with respect to x

Treat y as a constant, f(x,y) = x2y +3xy2

Differentiate:

2. Partial derivative with respect to y

Treat x as a constant, f(x,y) = x2y+ 3xy2

Differentiate:

Final Answers:

Comment

Explore