随机梯度下降(SGD)及正则化详解
1. 随机梯度下降(SGD)简介
随机梯度下降(SGD)是一种优化算法,在深度学习和机器学习中广泛应用。与标准的梯度下降不同,SGD在每次更新模型参数时,不是使用全部的训练数据,而是使用一个小批量的数据。这样做的好处是可以减少计算量,尤其在处理大规模数据集时非常有效。
2. 实现小批量SGD
以下是实现小批量SGD的详细步骤:
1. 创建新文件 :打开一个新文件,命名为 sgd.py ,并插入以下代码:
# import the necessary packages
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt
import numpy as np
import argparse
def sigmoid_activation(x):
# compute the sigmoid activation value for a given input
return 1.0 / (1 + np.exp(-x))
def predict(X, W):
# take the dot product between our features and weight matr
超级会员免费看
订阅专栏 解锁全文
1145

被折叠的 条评论
为什么被折叠?



