Python3 で sklearn を使用して SGDRegression フィットを確認したいのですが、実際には最小xの点で導関数がゼロです。
import numpy as np
from sklearn.linear_model import SGDRegressor
n_samples, n_features = 20, 3
rng = np.random.RandomState(0)
y = rng.randn(n_samples)
a = rng.randn(n_samples, n_features)
reg = SGDRegressor(loss="squared_loss", max_iter=1000, tol=1e-3)
reg.fit(a, y)
# Coefficients of the trained line
z = reg.coef_
# Derivative (gradient) on a[i1]
i1 = 1
grad_F1 = 2 * z * ((a[i1] * z) - y[i1])
grad_F1
np.linalg.norm(grad_F1) # 0.14034432156803853
期待どおりに 0 が得られないため、導関数の計算が間違っているか、最小化する x 値を取得する方法がありません。どんな助けでも感謝します、ありがとう。