Created
November 1, 2021 13:51
-
-
Save thomasnield/2defb663fc83c774b70e48e7703acb17 to your computer and use it in GitHub Desktop.
sympy_simple_linear_regression_derivatives.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sympy import * | |
m, b, i, n = symbols('m b i n') | |
x, y = symbols('x y', cls=Function) | |
sum_of_squares = Sum((m*x(i) + b - y(i)) ** 2, (i, 0, n)) | |
d_m = diff(sum_of_squares, m) | |
d_b = diff(sum_of_squares, b) | |
print(d_m) | |
print(d_b) | |
# OUTPUTS | |
# Sum(2*(b + m*x(i) - y(i))*x(i), (i, 0, n)) | |
# Sum(2*b + 2*m*x(i) - 2*y(i), (i, 0, n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment