码迷,mamicode.com
首页 > 编程语言 > 详细

Python之SGDRegressor

时间:2019-08-07 22:34:59      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:import   print   mode   迭代   class   结果   info   梯度下降   numpy   

 
实现:

# -*- 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)
结果:
技术图片

 

Python之SGDRegressor

标签:import   print   mode   迭代   class   结果   info   梯度下降   numpy   

原文地址:https://www.cnblogs.com/lvdongjie/p/11318001.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!