Partial derivatives in Machine Learning (original) (raw)

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.

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

f(x) = wx+b

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.

\frac{\partial J}{\partial w} = \frac{1}{m} \sum_{i=1}^{m} (wx_i + b - y_i) \cdot x_i ,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:

\omega = \omega - \alpha .\frac{\partial J}{\partial w}

b = b - \alpha .\frac{\partial J}{\partial b}

Where:

Implementation Of Partial derivatives in Machine Learning

import numpy as np

X = np.array([1, 2, 3, 4, 5]) y = np.array([100, 200, 300, 400, 500])

w = 0 b = 0 learning_rate = 0.01 epochs = 100

for epoch in range(epochs): predictions = w * X + b

dw = (1 / len(X)) * np.sum((predictions - y) * X)
db = (1 / len(X)) * np.sum(predictions - y)

w -= learning_rate * dw
b -= learning_rate * db

print("Optimal parameters: \n w =", w, "\n b =", b)

`

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: \frac{\partial f}{\partial x} = 2xy + 3y^2

**2. Partial derivative with respect to y

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

Differentiate: \frac{\partial f}{\partial y} = x^2 + 6xy

**Final Answers:

\frac{\partial f}{\partial x} = 2xy + 3y^2

\frac{\partial f}{\partial y} = x^2 + 6xy