• 随机梯度下降分类器和回归器


    随机梯度下降分类器并不是一个独立的算法,而是一系列利用随机梯度下降求解参数的算法的集合。

    SGDClassifier(分类):

    from sklearn.linear_model import SGDClassifier

    clf = SGDClassifier(loss="hinge", penalty="l2")

    loss function(损失函数):

    可以通过 loss 参数来设置。SGDClassifier 支持以下的 loss functions(损失函数):

    1)loss="hinge"                         (soft-margin) linear Support Vector Machine ((软-间隔)线性支持向量机),

    2)loss="modified_huber"          smoothed hinge loss (平滑的 hinge 损失),

    3)loss="log"                             logistic regression (logistic 回归),

    惩罚方法:

    惩罚方法可以通过 penalty 参数来设定。 SGD 支持以下 penalties(惩罚):

    penalty="l2":                L2 norm penalty on coef_.

    penalty="l1":                L1 norm penalty on coef_.

    penalty="elasticnet":     Convex combination of L2 and L1(L2 型和 L1 型的凸组合); (1 - l1_ratio) * L2 + l1_ratio * L1.

    支持多分类以及样本非均衡问题

    SGDRegressor

    损失函数:

    具体的损失函数可以通过 loss 参数设置。 SGDRegressor 支持以下的损失函数:

    loss="squared_loss":            Ordinary least squares(普通最小二乘法),

    loss="huber":                      Huber loss for robust regression(Huber回归),

    loss="epsilon_insensitive":   linear Support Vector Regression(线性支持向量回归).

    使用小贴士

    1、强烈建议缩放数据 :

    将输入向量 X 上的每个特征缩放到 [0,1] 或 [- 1,+1], 或将其标准化,使其均值为 0,方差为 1。

    from sklearn.preprocessing import StandardScaler

    scaler = StandardScaler()

    scaler.fit(X_train)

    假如你的 attributes (属性)有一个固有尺度(例如 word frequencies (词频)或 indicator features(指标特征))就不需要缩放。

    2、最好使用 GridSearchCV 找到一个合理的 regularization term (正则化项),它的范围通常在 10.0**-np.arange(1,7)

    3、经验表明,SGD 在处理约 10^6 训练样本后基本收敛。因此,对于迭代次数第一个合理的猜想是 n_iter = np.ceil(10**6 / n),其中 n 是训练集的大小。

    4、我们发现,当特征很多或 eta0 很大时, ASGD(平均随机梯度下降) 效果更好。

  • 相关阅读:
    【人生苦短,我学Python】个人学习笔记——str.count方法
    微信支付问题解决
    针对listview上面的按钮点击事件的操作
    Android界面之间的跳转和返回
    贪吃蛇
    数据库的连接
    Android中实现圆的面积的计算问题
    关于安卓环境的搭建问题
    python 获取cpu、内存、硬盘等实时信息 psutil
    python 配置文件
  • 原文地址:https://www.cnblogs.com/yongfuxue/p/9971836.html
Copyright © 2020-2023  润新知