我正在使用具有恒定学习率和默认损失函数的 SGDRegressor。我很想知道将函数中的 alpha 参数从 0.0001 更改为 100 将如何改变回归器的行为。以下是我的示例代码:
from sklearn.linear_model import SGDRegressor
out=[(0,2),(21, 13), (-23, -15), (22,14), (23, 14)]
alpha=[0.0001, 1, 100]
N= len(out)
plt.figure(figsize=(20,15))
j=1
for i in alpha:
X= b * np.sin(phi) #Since for every alpha we want to start with original dataset, I included X and Y in this section
Y= a * np.cos(phi)
for num in range(N):
plt.subplot(3, N, j)
X=np.append(X,out[num][0]) # Appending outlier to main X
Y=np.append(Y,out[num][1]) # Appending outlier to main Y
j=j+1 # Increasing J so we move on to next plot
model=SGDRegressor(alpha=i, eta0=0.001, learning_rate='constant',random_state=0)
model.fit(X.reshape(-1, 1), Y) # Fitting the model
plt.scatter(X,Y)
plt.title("alpha = "+ str(i) + " | " + "Slope :" + str(round(model.coef_[0], 4))) #Adding title to each plot
abline(model.coef_[0],model.intercept_) # Plotting the line using abline function
plt.show()
如上所示,我有 X 和 Y 的主要数据集,在每次迭代中,我将一个点作为异常值添加到主数据集并训练模型并绘制回归线(超平面)。您可以在下面看到不同 alpha 值的结果:
我正在查看结果,但仍然感到困惑,无法得出可靠的结论,因为 alhpa 参数如何改变模型?阿尔法的作用是什么?是否导致过拟合?欠拟合?
