Lv.的博客

Python之SGDRegressor

 

 
实现:

# -*- 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)
结果:

 

posted @ 2019-08-07 21:35  Avatarx  阅读(838)  评论(0编辑  收藏  举报