Код: Выделить всё
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
# Make or load an n x p data matrix X and n x 1 array y of the corresponding
# function values.
poly = PolynomialFeatures(degree=2)
Xp = poly.fit_transform(X)
model = LinearRegression()
model.fit(Xp, y)
# Approximate the derivatives of the gradient and Hessian using the relevant
# finite differences equations and model.predict.
Как указано выше, мой текущий обходной путь заключается в использовании уравнений конечных разностей и model.predict для аппроксимации элементов градиента и гессиана (как описано здесь). . Но мне не нравится такой подход. Есть ли более элегантный и точный метод в Python? Мне подойдет тот, который использует другую библиотеку.
Подробнее здесь: https://stackoverflow.com/questions/790 ... ensional-d