week2,有监督学习(的线性机器学习模型)

2017-06-22  本文已影响0人  __Jingyu__

2.1 有监督学习的描述:

有监督学习 是比较经典的一个机器学习场景。有监督学习可以被这样描述:

(1)Supervised learning is the machine learning task of inferring a function from labeled training data.[1] -监督学习完成“从labeled training data中推断出函数”的任务。
(2)labeled training data是由一对(input object, expected output)组成的数据。
(3)从labeled training data中学习到的函数可以将unseen instance的输入映射到输出(举个例子: 对于inferred function来说,我们再给它一个 input object 它就能够输出一个新的 expected output)。这种暗含在函数中的映射逻辑被称作inductive bias。(最简单的inductive bias就是occam's razor - Occam's razor, assuming that the simplest consistent hypothesis about the target function is actually the best. Here consistent means that the hypothesis of the learner yields correct outputs for all of the examples that have been given to the algorithm.)

最常用到的inductive bias:
Maximum conditional independence: if the hypothesis can be cast in a Bayesian framework, try to maximize conditional independence. This is the bias used in the Naive Bayes classifier.
Minimum cross-validation error: when trying to choose among hypotheses, select the hypothesis with the lowest cross-validation error. Although cross-validation may seem to be free of bias, the "no free lunch" theorems show that cross-validation must be biased.
Maximum margin: when drawing a boundary between two classes, attempt to maximize the width of the boundary. This is the bias used in support vector machines. The assumption is that distinct classes tend to be separated by wide boundaries.
Minimum description length: when forming a hypothesis, attempt to minimize the length of the description of the hypothesis. The assumption is that simpler hypotheses are more likely to be true. See Occam's razor.
Minimum features: unless there is good evidence that a feature is useful, it should be deleted. This is the assumption behind feature selection algorithms.
Nearest neighbors: assume that most of the cases in a small neighborhood in feature space belong to the same class. Given a case for which the class is unknown, guess that it belongs to the same class as the majority in its immediate neighborhood. This is the bias used in the k-nearest neighbors algorithm. The assumption is that cases that are near each other tend to belong to the same class.

2.2 有监督学习(supervised learning)的主要步骤:

(1)任务导向部分:
确定监督学习任务

确定训练集的数据类型(图像,数字,音频?)

(2)数据工程部分:
收集训练集,数据预处理

(3)特征工程部分:
从数据集中选择有可能有用的特征,特征预处理, curse of dimensionality;

(4)模型工程部分:
根据任务特点选择有监督学习算法(不同的监督学习算法定义了不同的函数式,这里又叫hypothesis) ,如何合理地选择模型,衡量不同模型的优缺点参考:No free lunch theorem

(5)模型训练工程:
训练模型,计算cost function,计算optimization function,可视化训练结果,把握好underfitting和overfitting,调整模型参数,继续训练模型

(6)模型评估工程:
评估模型,交叉验证,模型泛化能力 cross-validation.

这些步骤里面, “训练,计算cost function,使用optimization function” 这三步是需要迭代多次才能得到优秀结果的。
此外

2.2.1 任务导向

2.1.1 分类任务
(1) 分类任务有两种:

分类任务有两种,其一是二分类任务,其二是多分类任务。
通常在实际应用中,都是多分类任务。

2.2.2 数据工程

2.2.3 特征工程

2.2.4 模型工程部分

2.2.4.1 分类模型
(1) 分类模型有两种:

分类任务有两种,其一是二分类任务,其二是多分类任务。
有监督学习里面可以的分类器,有适合做二分类的分类器(logistic regression, basic SVM)和天生就适合做多分类的分类器(K近邻,神经网络,朴素贝叶斯,决策树,拓展SVM)。

2.2.4.2使用分类模型执行分类任务
(1) 执行二分类任务:

二分类任务是最直接的分类任务,同时也是多分类任务的基础。
二分类任务主要步骤:

举个例子:
<1> 选择分类模型:
假设使用logistic regression作二分类问题
logistic regression的hypothesis(即模型的函数表达式)是:

(theta 和 x都是 N维向量,N代表输入特征个数)

其hypothesis的函数图像是:


(纵轴是h_theta(x),横轴是 -theta*x)

<2> 设定有第0类和第1类:


<3> 我们设定阈值为: h_theta(x)=0.5。 分类规则为:小于0.5算作第0类, 大于0.5算作第1类。则此时可知:

(2) 执行多分类任务

多分类任务的重点在于‘进行多分类的手段’,常见应用于解决多分类问题的方法有三种:

The existing multi-class classification techniques can be categorized into (i) Transformation to binary (ii) Extension from binary and (iii) Hierarchical classification.[1] -三种解决多分类问题的方法:
1.将多分类问题拆分成多个二分类问题(常见的手段有:one-vs-all/又叫one-vs-rest, 和 one-vs-one又叫all-vs-all)
2.将二分类技术拓展成多分类技术(如:拓展SVM,神经网络)
3.进行层次分类

<1> 将多分类问题拆成多个二分类问题:

one-vs-all(one-vs-rest)

one-vs-all的主要思想就是:

one-vs-one(all-vs-all)

one-vs-one的主要思想就是:

<2> 二分类模型拓展成多分类模型:
以下分类器可以直接进行多分类:

<3> 进行层次分类:

Hierarchical classification tackles the multi-class classification problem by dividing the output space i.e. into a tree. Each parent node is divided into multiple child nodes and the process is continued until each child node represents only one class. Several methods have been proposed based on hierarchical classification.
--层次分类法首先将所有类别分成两个子类,再将子类进一步划分成两个次级子类,如此循环,直到得到一个单独的类别为止。对层次支持向量机的详细说明可以参考论文《支持向量机在多类分类问题中的推广》

2.2.4.3 分类模型详解

(1) Logistic Regression(逻辑回归)
Logistic Regression是由一种基于概率解释的线性分类模型,可以解决:
<1> 二分类问题(使用sigmoid function将函数值映射到(0,1)概率区间内)
<2> 多分类问题(需要用到one-vs-all或者one-vs-one)。
Logistic Regression的模型(hypothesis)可以说是用 sigmoid function套上Linear Regression的hypothesis得来的。

(2) Support Vector Machine(支持向量机)
支持向量机作为同时支持线性和非线性分类的分类模型,也支持二分类和多分类问题。SVM的算法模型

2.2.4.4 回归任务(经常用于预测) !!!!这里涉及大量统计学,还需要学习后补全知识点

回归的定义:回归是一种估计自变量(independent variable)和因变量(dependent variable)之间的对应关系的统计学方法。- 以统计学的角度说,回归就是:regression analysis estimates the conditional expectation of the dependent variable given the independent variables。

2.2.5 模型训练工程

监督学习的cost function(还需完善)

In statistics, typically a loss function is used for parameter estimation, and the event in question is some function of the difference between estimated and true values for an instance of data. supervised learning tasks such as regression or classification can be formulated as the minimization of a loss function over a training set. Hence,The loss function quantifies the amount by which the prediction deviates from the actual values. --在统计学中,loss function被用在参数估计中。而监督学习的方法,从参数估计的角度来说可以被定义为:“监督学习就是那些通过不断修改自身模型(函数)的参数从而达到满意效果的regression 或者 classification任务”。 因此,监督学习天然地需要借用cost function作为参数估计的手段,使用cost function去估量:当前的监督学习模型的参数估计的结果和真实参数的差距。

常见的Loss function:
包括log对数损失函数,平方损失函数,指数损失函数,Hinge损失函数

常见的optimization function(还需完善)

我目前知道的包括 梯度下降, normal equation, conjugate gradient, BFGS, L-BFGS

常见的有监督学习算法:
hypothesis

hypothesis在这里被用在有监督学习的线性学习方法的函数表示上。
比如: linear regression 的 hypothesis 就可以是:


这是一个具有一维特征的linear regression hypothesis。
其中, theta代表hypothesis中的参数,x uppercase i代表第i个样本的输入特征值。

损失函数详解
线性有监督机器学习后三步的细节

我们后面为了cost function 和 optimization function方便,需要假设x0 = 1.
所以我们有:


其中,y uppercase i值得是对应于第i个输入训练样本的期望输出expected output。
这里设置1/2m而不是1/m的原因是我们后面会使用gradient descent作为optimization function,而gradient descent其中有求导数的步骤,那么指数2和分数1/2就会抵消掉,这样就简化了计算。

注意,对于所有的theta 我们需要同时进行更新。

image.png
上一篇 下一篇

猜你喜欢

热点阅读