实现:
# -*- coding: UTF-8 -*-
import numpy as np
from sklearn.linear_model import SGDRegressor
__author__ = ‘zhen‘
X = 2 * np.random.rand(100, 1)
y = 4 + 3 * X + np.random.randn(100, 1)
# 梯度下降回归
sgd_reg = SGDRegressor(max_iter=100) # 最大迭代次数
sgd_reg.fit(X, y.ravel())
print("="*50)
print(sgd_reg.predict(1.5)) # 预测
print("W0=", sgd_reg.intercept_)
print("W1=", sgd_reg.coef_)
print("="*50)
结果: