前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Using Stochastic Gradient Descent for classification使用随机梯度下降来分类

Using Stochastic Gradient Descent for classification使用随机梯度下降来分类

作者头像
到不了的都叫做远方
修改2020-05-06 11:44:39
4910
修改2020-05-06 11:44:39
举报

As was discussed in Chapter 2, Working with Linear Models, Stochastic Gradient Descent is a fundamental technique to fit a model for regression. There are natural connections between the two techniques, as the name so obviously implies.

正如在第二章讨论的运行线性模型,随机梯度下降对于拟合回归模型是一个基本的技术,在两个技术间,像它们的名字指出的那样有些自然联系。

Getting ready准备工作

In regression, we minimized a cost function that penalized for bad choices on a continuous scale, but for classification, we'll minimize a cost function that penalizes for two (or more) cases.

在回归模型中,我们用惩罚在连续范围内的错误选择来最小化代价函数,但是对于分类方法,我们用惩罚两个或多个例子来最小化损失函数。

How to do it…怎么做

First, let's create some very basic data:首先,让我们生成一些非常基本的数据集。

代码语言:javascript
复制
from sklearn import datasets
X, y = datasets.make_classification()

Next, we'll create a SGDClassifier instance:然后,我们将生成一个SGDClassifier例子

代码语言:javascript
复制
from sklearn import linear_model
sgd_clf = linear_model.SGDClassifier()

As usual, we'll fit the model:和以前一样,来拟合模型:

代码语言:javascript
复制
sgd_clf.fit(X, y)
SGDClassifier(alpha=0.0001, average=False, class_weight=None,
              early_stopping=False, epsilon=0.1, eta0=0.0, fit_intercept=True,
              l1_ratio=0.15, learning_rate='optimal', loss='hinge',
              max_iter=1000, n_iter_no_change=5, n_jobs=None, penalty='l2',
              power_t=0.5, random_state=None, shuffle=True, tol=0.001,
              validation_fraction=0.1, verbose=0, warm_start=False)

We can set the class_weight parameter to account for the varying amounts of unbalance in a dataset.

我们能设置class_weight参数来调整数据集中不均衡的变化情况。

The Hinge loss function is defined as follows:以下是定义的hinge损失函数

Here, t is the true classification denoted as +1 for one case and -1 for the other. The vector of coefficients is denoted by y as fit from the model, and x is the value of interest. There is also an intercept for good measure. To put it another way:

这里,t是一个真实的分类标志+1为一类和-1为另一类。系数的矢量被标志模型中拟合的y。x是感兴趣的一个值。一般还有个额外的截距,展示为另一种方法。

本文系外文翻译,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系外文翻译前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
作者已关闭评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档