菜品三级分类

Many tasks in Machine Learning are setup as classification tasks. The name would imply you have to learn a classifier to solve such a task. However, there are many popular alternatives to solving classification tasks which do not involve training a classifier at all!

机器学习中的许多任务都设置为分类任务。 该名称意味着您必须学习分类器才能解决此类任务。 但是,有许多解决分类任务的流行替代方法,这些方法根本不需要训练分类器!

分类任务示例 (An Example Classification Task)

For the purpose of illustrating these alternative methods, let’s use a very simple, yet visual classification problem. Our dataset shall be a random image from the internet. But only a single image… of Ironman!

为了说明这些替代方法,让我们使用一个非常简单但直观的分类问题。 我们的数据集应该是来自互联网的随机图像。 但是只有一个图像……铁人三项!

Each image pixel of this image will count as a unique data sample. Our set of inputs (X) shall be the pixel coordinates and our set of outputs (Y) shall be the pixel colours.

该图像的每个图像像素将被视为唯一的数据样本。 我们的一组输入(X)应该是像素坐标,而我们的一组输出(Y)应该是像素颜色。

The classification task is to predict a pixel colour (y) given a coordinate (x).

分类任务是在给定坐标(x)的情况下预测像素颜色(y)。

  • Inputs (X) = pixel coordinates
    输入(X)=像素坐标
  • Outputs (Y) = pixel colour class
    输出(Y)=像素颜色类别

We can convert the pixel’s continuous RGBA colour vector into a discrete, categorical class index, so that this toy classification task is simplified.

我们可以将像素的连续RGBA颜色向量转换为离散的分类类别索引,从而简化了此玩具分类任务。

The 5 colour classes for our toy classification task
我们的玩具分类任务的5种颜色类别

火车测试拆分 (The Train-Test Split)

As a small aside, when splitting the dataset into a training set and a test set, they should have a similar distribution. This means we cant simply split the data down the middle, because the distribution of data that we would test our results on would be very different to the data we used in training (thus leading to bad and/or misleading results)

另外,将数据集分为训练集和测试集时,它们应该具有相似的分布。 这意味着我们不能简单地将数据拆分到中间,因为我们用来测试结果的数据分布将与我们在训练中使用的数据完全不同(从而导致不良和/或误导性的结果)

(Left) How NOT to split your data. (Right) Bad results. Test Predictions from a classifier trained on the top Train data which has a very different distribution to the test data
(左)如何不分割数据。 (正确)不好的结果。 来自在顶部训练的分类器的测试预测训练数据与测试数据的分布非常不同

That is why you should take care when preparing your data (this is all taken care of in the background when using statistical libraries like sklearn)

这就是为什么在准备数据时要小心(在使用sklearn之类的统计库时,所有这些操作都在后台处理)

from sklearn.model_selection import train_test_splitX_train, X_test, Y_train, Y_test = train_test_split(X, Y)
Much better. The training set and test set have been split in such a way to keep similar distributions.
好多了。 训练集和测试集已按照保持相似分布的方式进行了拆分。

混乱矩阵 (The Confusion Matrix)

We shall use a confusion matrix to plot how well our method classified the colour for each pixel coordinate in the test set. A perfect classification would look like the confusion matrix below:

我们将使用混淆矩阵来绘制我们的方法对测试集中每个像素坐标的颜色分类的程度。 完美的分类看起来像下面的混淆矩阵:

Confusion Matrix plotting an Ideal Classification
混淆矩阵绘制理想分类

1.直接方法:学习分类器 (1. The Direct Approach: Learn a Classifier)

Now most people solve classification tasks by training a classifier — i.e. Learning a nonlinear function (f) (the classifier) which maps a set of inputs (X) to a set of outputs (Y).

现在,大多数人通过训练分类器来解决分类任务,即学习将一组输入(X)映射到一组输出(Y)的非线性函数(f)(分类器)。

Let us do that too so we have a baseline solution to this classification task to compare against. There are a range of ML models out there to approximate a nonlinear function (the classifier) — but we shall simply use a feed-forward neural network with 3 hidden layers (100 neurons per layer)

让我们也这样做,以便针对此分类任务有一个基准解决方案。 有大量的ML模型可以近似非线性函数(分类器),但是我们将简单地使用具有3个隐藏层(每层100个神经元)的前馈神经网络。

training our classifier
训练我们的分类器

The results were not bad. They weren’t perfect — but it does a good enough job on our toy classification task (despite occasionally missing off the right eye of ironman)

结果还不错。 它们并不完美-但这在我们的玩具分类任务中做得足够好(尽管偶尔会遗忘Ironman的右眼)

Three trained instances of our classifier predicting the pixel colours on the ironman test set.
分类器的三个经过训练的实例可以预测Ironman测试集上的像素颜色。

2.替代方法:排名 (2. Alternative Approaches: Ranking)

Ranking (aka Retrieval) is a widely used alternative to training a function (classifier) which directly predicts an output for a given input. By measuring the distance of an input (x) to an output (y), a given input can be ranked against a range of outputs and the best can then be selected (retrieved). Ranking like this is an indirect way to map a given input (x) to an output (y) without requiring a trained classifier (f). Or another way to think about it is — you have decomposed your classifier (f) into an evaluation/distance function (Q) and ranking algorithm (arg max).

排名(又名检索)是训练功能(分类器)的一种广泛使用的替代方法,该功能可直接预测给定输入的输出。 通过测量输入(x)到输出(y)的距离,可以将给定输入与一系列输出进行比较,然后选择最佳(检索)。 这样的排名是一种将给定输入(x)映射到输出(y)的间接方法,而无需训练有素的分类器(f)。 或考虑它的另一种方法是-您已将分类器(f)分解为评估/距离函数(Q)和排名算法(arg max)。

The infamous Q-function equation in RL is actually an example of ranking to classify if we interpret the notation as: input (s), output (a), distance function (Q)
RL中臭名昭著的Q函数方程实际上是排名的一个示例,如果我们将符号解释为以下类别,则可以将其解释为:输入(s),输出(a),距离函数(Q)

However, doesn’t this mean you just substituted one type of problem for another ? Haven’t you just shifted the problem of learning one function (the classifier) for another function (the distance function)? Yes — but… the latter function may be much easier to learn or you may not even need to learn a distance function if you can use a predefined distance measure (e.g. euclidean distance, cosine similarity, etc).

但是,这是否意味着您只是将一种问题替换为另一种问题? 您是否刚刚将学习一个功能(分类器)的问题转移到了另一个功能(距离函数)的问题? 是的,但是…如果您可以使用预定义的距离度量(例如,欧几里德距离,余弦相似度等),则后者功能可能更容易学习,或者甚至不需要学习距离功能。

2.a K最近的邻居 (2.a K Nearest Neighbours)

K nearest neighbours (KNN) is actually a very well known ranking algorithm used to solve classification tasks. It essentially ranks the new input (x) against a set of K example inputs using a linear distance measure (e.g. euclidean, cosine, etc) and then uses the output (y) of the most similar example input as its prediction.

K最近邻居(KNN)实际上是一种非常著名的排序算法,用于解决分类任务。 它实质上使用线性距离度量(例如,欧几里得,余弦等)针对一组K个示例输入对新输入(x)进行排名,然后将最相似的示例输入的输出(y)用作其预测。

The KNN algorithm is one of the simpler forms of machine learning known as example-based learning (aka retrieval-based learning, instance-based learning, lazy learning, etc), as it relies on memorising examples to avoid learning / approximating a function. It simply uses an off-the-shelf distance function to compare inputs against memorised, exemplar inputs (embedded in the same space).

KNN算法是机器学习的一种较简单形式,称为基于实例的学习(又名基于检索的学习,基于实例的学习,惰性学习等),因为它依靠记忆示例来避免学习/逼近功能。 它仅使用现成的距离函数将输入与记忆的,示例性的输入(嵌入在同一空间中)进行比较。

from sklearn.neighbors import KNeighborsClassifiernearest_neighbour_algorithm = KNeighborsClassifier(n_neighbors=3)nearest_neighbour_algorithm.fit(X_train, Y_train)Y_predicted = nearest_neighbour_algorithm.predict(X_test)

Almost perfect Test Predictions for the KNN method
KNN方法的几乎完美的测试预测

Siamese Networks actually work on a very similar principal to KNNs (i.e. they compare new inputs to exemplar inputs to retrieve their corresponding outputs), however it learns its own, custom distance function.

暹罗网络实际上在与KNN相似的原理上工作(即,它们将新输入与示例输入进行比较以检索其相应的输出),但是它学习了自己的自定义距离函数。

Siamese Neural Network
暹罗神经网络

2.b联合嵌入 (2.b Joint Embeddings)

We can get away with using custom distance functions by comparing inputs (x) with other inputs (x) which are embedded in the same space. However, this is more tricky when measuring the distance between inputs (x) with outputs (y) directly due to them being embedded in two different spaces. We can overcome this by using joint embeddings (i.e. embedding the inputs and outputs in a shared space).

通过将输入(x)与嵌入在同一空间中的其他输入(x)进行比较,我们可以使用自定义距离函数。 但是,由于直接将输入(x)嵌入两个不同的空间中,因此在直接测量输入(x)与输出(y)之间的距离时,这比较棘手。 我们可以通过使用联合嵌入(即将输入和输出嵌入到共享空间中)来克服这一问题。

examples of joint embeddings
联合嵌入的例子

Therefore this method involves learning joint embeddings such that the inputs (X) and outputs (Y) can be embedded into a shared space. Then we can rank a new input against the outputs using linear distance metrics (e.g. euclidean distance, cosine distance, etc). There are a few different ways to embed the outputs and inputs onto a shared manifold — such as taking the learnt feature representations of a neural model (e.g. Recurrent Embedding Dialogue Policy, etc).

因此,该方法涉及学习联合嵌入,以便可以将输入(X)和输出(Y)嵌入到共享空间中。 然后,我们可以使用线性距离度量(例如,欧几里得距离,余弦距离等)对输出进行新排序。 有几种不同的方法可以将输出和输入嵌入到共享的流形中,例如采用神经模型的学习到的特征表示(例如,循环嵌入对话策略等)。

We shall be using Matrix Factorisation.

我们将使用矩阵分解。

(Right) The Outputs embedded into the input’s XY coordinate space using Matrix Factorisation
(右)使用矩阵分解将输出嵌入到输入的XY坐标空间中
Test Predictions using the learnt joint embeddings
使用学习的联合嵌入进行测试预测

2.c学习距离函数 (2.c Learning a Distance Function)

You can also approximate a custom, nonlinear distance measure which would have learnt to measure the relative distances of input-output pairs (despite being embedded differently). We can do this by feeding in a set of concatenated input-output vectors as the model input, and training the model to predict a distance score (a value between 0 and 1) for the concatenated input-output pair.

您也可以近似自定义的非线性距离度量,该度量将学会测量输入-输出对的相对距离(尽管嵌入方式有所不同)。 我们可以通过输入一组串联的输入-输出向量作为模型输入,并训练模型以预测串联的输入-输出对的距离得分(0到1之间的值)来做到这一点。

We therefore modify the training data by concatenating inputs and outputs randomly (to become our new training inputs) and setting their expected distance to 0 if the input-output pair is a valid mapping,and 1 if its an invalid input-output mapping. The model used to approximate the distance function is simply a feedforward neural network (with 3 hidden layers, each with 100 neurons) almost identical to the one used for the classifier method (except this neural network is set up for learning a regression task as opposed to a classification task).

因此,我们通过以下方式修改训练数据:将输入和输出随机串联(以成为新的训练输入),如果输入/输出对是有效映射,则将其期望距离设置为0;如果输入/输出对是无效输入,则将其期望距离设置为1。 用于近似距离函数的模型只是一个前馈神经网络(具有3个隐藏层,每个具有100个神经元),几乎与用于分类器方法的模型相同(除了该神经网络是为学习回归任务而设置的)到分类任务)。

Training a feedforward neural network to be a nonlinear distance function (aka cost function). Input = Input-Output pair. Ouput=distance.
将前馈神经网络训练为非线性距离函数(又称成本函数)。 输入=输入-输出对。 输出=距离。
Test Predictions using the Learnt Distance Function
使用学习的距离函数进行测试预测

结论 (Conclusion)

Performance wise, the results of the alternative methods were similar to the classifier, however, retrieval based methods do present additional benefits over a classifier in other areas, like adding a stochastic element (if the top ranking result is always chosen it is identical to using a classifier or another deterministic mapping, however, adding some uncertainty can be done by ensuring the top ranking result is not always chosen), or like updating classes more easily, solving much larger multiclass classification problems (i.e. those with hundreds of classes) and being able to solve multilabel classification problems (i.e. predicting the top N applicable outputs for a given input), etc.

在性能方面,替代方法的结果类似于分类器,但是基于检索的方法在其他领域确实比分类器具有更多优势,例如添加随机元素(如果始终选择排名最高的结果,则等同于使用分类器或其他确定性映射,但是,可以通过确保不总是选择排名最高的结果来增加一些不确定性,或者像更轻松地更新类,解决更大的多类分类问题(即具有数百个类的问题)并能够解决多标签分类问题(即预测给定输入的前N个适用输出)等。

谢谢 (Thanks)

Thanks for reading. All the code is included in the attached Colab notebook. Have fun experimenting

谢谢阅读。 所有代码都包含在随附的Colab笔记本中。 尝试愉快

翻译自: https://medium.com/swlh/amazing-alternatives-to-classifiers-b7bd7e85b60d

菜品三级分类

http://www.taodudu.cc/news/show-863780.html

相关文章:

  • 开关变压器绕制教程_教程:如何将变压器权重和令牌化器从AllenNLP上传到HuggingFace
  • 一般线性模型和混合线性模型_线性混合模型如何工作
  • 为什么基于数字的技术公司进行机器人研究
  • 人类视觉系统_对人类视觉系统的对抗攻击
  • 在神经网络中使用辍学:不是一个神奇的子弹
  • 线程监视器模型_为什么模型验证如此重要,它与模型监视有何不同
  • dash使用_使用Dash和SHAP构建和部署可解释的AI仪表盘
  • 面向表开发 面向服务开发_面向繁忙开发人员的计算机视觉
  • 可视化 nltk_词嵌入:具有Genism,NLTK和t-SNE可视化的Word2Vec
  • fitbit手表中文说明书_使用机器学习预测Fitbit睡眠分数
  • redis生产环境持久化_在SageMaker上安装持久性Julia环境
  • alexnet vgg_从零开始:建立著名的分类网2(AlexNet / VGG)
  • 垃圾邮件分类 python_在python中创建SMS垃圾邮件分类器
  • 脑电波之父:汉斯·贝格尔_深度学习,认识聪明的汉斯
  • PyCaret 2.0在这里-新增功能?
  • 特征选择 回归_如何执行回归问题的特征选择
  • 建立神经网络来预测贷款风险
  • redshift教程_分析和可视化Amazon Redshift数据—教程
  • 白雪小町_町
  • 机器学习术语_机器学习术语神秘化。
  • centos有趣软件包_这5个软件包使学习R变得有趣
  • 求解决方法_解决方法
  • xml格式是什么示例_什么是对抗示例?
  • mlflow_在生产中设置MLflow
  • 神秘实体ALIMA
  • mnist数据集彩色图像_使用MNIST数据集构建多类图像分类模型。
  • bert使用做文本分类_使用BERT进行深度学习的多类文本分类
  • 垃圾邮件分类器_如何在10个步骤中构建垃圾邮件分类器
  • ai 图灵测试_适用于现代AI系统的“视觉图灵测试”
  • pytorch图像分类_使用PyTorch和Streamlit创建图像分类Web应用

菜品三级分类_分类器的惊人替代品相关推荐

  1. 使用java怎么实现商品三级分类_如何实现列表三级分类---后端+前端

    对于分类来说,一般包括一级分类,二级分类,三级分类, 大部分网站都是左边点击二级分类,右边显示相对应商品 下面就来为大家详细分析一下该如何实现吧. 如图: 分析图 1.1后端实现:JavaBean 与 ...

  2. 糖药病数据集分类_使用optuna和mlflow进行心脏病分类器调整

    糖药病数据集分类 背景 (Background) Data science should be an enjoyable process focused on delivering insights ...

  3. sql语句查询商品的一二三级分类都是一个字段怎么办_畅购商城(三):商品管理...

    好好学习,天天向上 本文已收录至我的Github仓库「DayDayUP」:github.com/RobodLee/DayDayUP,欢迎Star 小练手 这里有三个小练手的任务,内容比较简单,就是对一 ...

  4. php 根据父级id查出,php,_三级分类 like查询 查询到很多id 需要找到对应的父级id 并根据父级id组合 应该怎么根据父级id将数据组合在一起呢?,php - phpStudy...

    三级分类 like查询 查询到很多id 需要找到对应的父级id 并根据父级id组合 应该怎么根据父级id将数据组合在一起呢? 这是获取到的数据 父级id为parent_id Array ( [0] = ...

  5. 图卷积 节点分类_在节点分类任务上训练图卷积网络

    图卷积 节点分类 This article goes through the implementation of Graph Convolution Networks (GCN) using Spek ...

  6. 小程序分类页实现三级分类,顶部导航栏,左侧分类栏,右侧数据列表

    如果大家一直读石头哥的文章,或者看石头哥的视频,肯定知道,石头哥的点餐小程序有实现二级菜品或者商品分类. 如下图 但是有时候我们想实现三级分类,该怎么做呢,今天就来教大家如何实现三级分类.随便教下大家 ...

  7. 谷粒商城之商品服务-三级分类(展示与删除)

    目录 三级类目查询后台代码实现 后台管理系统的菜单创建 配置网关和路径重写 网关统一配置跨域 三级类目后台管理系统的页面显示 三级分类删除页面效果的编写 ​ 三级分类逻辑删除后台实现 三级类目删除功能 ...

  8. 实操:商品列表三级分类的实现方法

    对于分类来说,一般包括一级分类,二级分类,三级分类,一般2级分类是比较好做的,大部分网站都是左边点击二级分类,右边显示相对应商品,这就要用到jquery技术了.下面就来为大家详细分析一下该如何实现吧. ...

  9. vue一级分类和耳机分类_【Vue+DRF生鲜电商】10.商品分类层级获取,Vue跨域请求商品分类...

    欢迎访问我的博客专题 源码可访问 Github 查看 DRF实现商品分类获取 实现商品分类层级结构显示 商品类别ViewSet 在商品类别中,不需要对类别进行分页,因为类别的数据量不大,只要在数据量很 ...

最新文章

  1. 干货 | 拒当调参师工程师:超参数搜索算法一览
  2. python添加模块搜索路径
  3. 德黑兰大学推可踢球机器人,中国队快买!
  4. 主流Java报表工具的比较
  5. POJ 1185 解题报告 炮兵阵地
  6. IbatisNet开发使用小结
  7. Scala @BeanProperty注解生成getter/setter
  8. python oracle orm_Python ORM
  9. 重庆市大学生程序设计比赛相关情况
  10. Position independent code and data (ROPI and RWPI)
  11. 3-17Pytorch与线性代数运算
  12. 前端埋点方法解析及优缺点分析
  13. 计算机有损压缩编码,有损压缩格式有哪些
  14. jsp中打开新的html网页,jsp中用window.open()打开新页面的相关设置
  15. RSA加密应用常见缺陷的原理与实践
  16. C++ 多种定义的getline函数使用
  17. linux内核机制之设备树
  18. ag-grid 学习
  19. cron定时任务详解
  20. ADS滤波器设计向导工具一

热门文章

  1. perl anyevent socket监控web日志client
  2. 解决jsp两种提交方式乱码 的方法
  3. WAF指纹识别和XSS过滤器绕过技巧
  4. html中的div span和frameset框架标签
  5. Java 技术小图谱
  6. Atitit.json类库的设计与实现 ati json lib
  7. Gstreamer编程
  8. 苹果公司的新的编程语言 Swift 高级语言()两--基本数据类型
  9. SMG12232A2标准图形点阵型液晶显示模块的演示程序[C51编程语言]
  10. java删除文件夹的所有文件