三、sklearn实现梯度下降

1、梯度下降的概念

  https://1drv.ms/u/s!AlpiCfg9Lzmug1Dj69iU4OC0Rpt-

2、梯度下降的类型

  • 批量梯度下降
  • 随机梯度下降
  • 小批量梯度下降

3、sklearn实现梯度下降

# 随机梯度下降
from sklearn.linear_model import SGDRegressor

from sklearn.preprocessing import StandardScaler

# 归一化数据
std = StandardScaler()
std.fit(X_train)
X_train_std = std.transform(X_train)
X_test_std = std.transform(X_test)

# n_iter代表浏览多少次,默认是5
sgd_reg = SGDRegressor(n_iter=100)
sgd_reg.fit(X_train_std, y_train)
sgd_reg.score(X_test_std, y_test)
View Code

 

posted @ 2019-03-01 21:25  起航追梦人  阅读(2592)  评论(0编辑  收藏  举报