[machine learning] Loss Function view

[machine learning] Loss Function view

有关Loss Function(LF),只想说,终于写了

一、Loss Function

什么是Loss Function?wiki上有一句解释我觉得很到位,引用一下:The loss function quantifies the amount by which the prediction deviates from the actual values。Loss Function中文损失函数,适用于用于统计,经济,机器学习等领域,虽外表形式不一,但其本质作用应是唯一的,即用于衡量最优的策略。本章只从机器学习(ML)领域来对其进行阐述,机器学习其实是个不停的模拟现实的过程,比如无人驾驶车,语音识别,流感预测,天气预报,经济周期行为等众多领域,是互联网发展过程中“科学家”(暂且这么称呼吧)对于人类文明进步的另一个贡献,其本质就是要建立一个数学模型用于模拟现实,越接近真实越好,那么转化为数学语言即LF越小越好,因为LF值代表着现实与学习预测的差距,这个不停的缩小LF值的过程就称为优化,如果理解这些的话,就不难理解优化问题对于ML来说的重要性了,如水之于鱼,魂之于人!

二、几种Loss Function概述

如上一节所述,LF的概念来源于机器学习,同时我们也知道机器学习的应用范围相当广泛,几乎可以涵盖整个社会领域,那么自然不同的领域多少会有不同的做法,这里介绍在一般的机器学习算法中常见的几种,具有概括性

2.1 一般形式

J(w)=∑iL(mi(w))+λR(w)

LF分为两部分:L+R,L表示loss term,其中mi(w)=y(i)wTxi,y(i)∈{−1,1},w表示学习出来的权重,该公式的作用很明显了,用来收集现实与学习结果的差距,是LF的核心部分,LF的不同大部分也是指的loss term的不同;R表示范式,范式存在的意思是进行约束,以防止优化过偏。

2.2 一般的loss term有5种,分别用于5种常见的机器学习算法

Gold Standard(标准式)于理想sample,这种一般很少有实践场景,这个方法的作用更多的是用来衡量其他LF的效用;Hinge于soft-margin svm算法;log于LR算法(Logistric Regression);squared loss于线性回归(Liner Regression)和Boosting。

1)Gold Standard loss,一般我们称这个LF为L01,从公式中可以看出该公式的主要职责是在统计多少个错误的case,很明显现实数据不允许如此简单的统计方式

从公式我们可以很清楚的看出,当m<0的时候L=1,m<0说明预测失败,那么Loss则加1,这样将错误累加上去,就是Gold Standard loss的核心思想。

2)hinge loss,常用于“maximum-margin”的算法,公式如下

l(y)=max(0,1−mi(w))

这个公式也很好理解,其中mi(w)在前面介绍过,表示样本i在模型下的预测值的样本i的类标记{-1,1}的乘积,这个乘积可以用来检验预测与真实结果是否一致来表示分类是否正确,当乘积大于0时表示分类正确,反之亦然。

3) log loss(一般又称为基于最大似然的负log loss)

likelihood=

l(y)=−likelihood

其中 是log函数

最大似然思想指的是使得某种情况发生的概念最大的思想,根据LR的思想(参考这篇文章logistic回归深入篇(1)),我们知道g(w)对应的simod图,其将实域上的值映射到区间{0,1},因此我们可以把g(w)看作事件A发生的概率,那么1-g(w)可以看作事件A不发生的概率,那么公式likelihood表达的含义就很明显了,y也是一个概率值,可以看做是对事件A与A逆的分量配额,当然我们的期望是A发生的可能越大越好,A逆发生的可能越小越好!因此likelihood是一个max的过程,而loss是一个min的过程,因此log loss是负的likelihood。

4)square loss

这个loss很好理解,就是平方差,loss 一般也成为最小二乘法

5)boosting loss

这个loss主要是基于指数函数的loss function。

三、几种Loss Function的效果对比

上图是多LF的效果对比图,其中蓝色的是Gold loss,可以看作水平基线,其他的loss的效果可以基于与它的比较结果,首先,红色的是Hinge loss,黄色的是log loss,绿色的是boosting loss,黑色的是square loss,从上图可以看出以下结论: Hinge,log对于噪音函数不敏感,因为当m<0时,他们的反应不大,而黑线与绿线可能更爱憎分明,尤其是黑线,因此,在很多线性分类问题中,square loss也是很常见的LF之一。

本文版权属作者@eletva所有,转载须注明出处,谢谢

损失函数(loss function)

通常而言,损失函数由损失项(loss term)和正则项(regularization term)组成。发现一份不错的介绍资料:

http://www.ics.uci.edu/~dramanan/teaching/ics273a_winter08/lectures/lecture14.pdf (题名“Loss functions; a unifying view”)。

一、损失项

  • 对回归问题,常用的有:平方损失(for linear regression),绝对值损失;
  • 对分类问题,常用的有:hinge loss(for soft margin SVM),log loss(for logistic regression)。

说明:

  • 对hinge loss,又可以细分出hinge loss(或简称L1 loss)和squared hinge loss(或简称L2 loss)。国立台湾大学的Chih-Jen Lin老师发布的Liblinear就实现了这2种hinge loss。L1 loss和L2 loss与下面的regularization是不同的,注意区分开。

二、正则项

  • 常用的有L1-regularization和L2-regularization。上面列的那个资料对此还有详细的总结。

补充

时间: 2024-08-25 06:58:34

[machine learning] Loss Function view的相关文章

Machine Learning - Neural Networks Learning: Cost Function and Backpropagation

This series of articles are the study notes of " Machine Learning ", by Prof. Andrew Ng., Stanford University. This article is the notes of week 5, Neural Networks Learning. This article contains some topic about Cost Function and Backpropagatio

A Gentle Introduction to the Gradient Boosting Algorithm for Machine Learning

A Gentle Introduction to the Gradient Boosting Algorithm for Machine Learning by Jason Brownlee on September 9, 2016 in XGBoost 0 0 0 0 Gradient boosting is one of the most powerful techniques for building predictive models. In this post you will dis

[C5] Andrew Ng - Structuring Machine Learning Projects

About this Course You will learn how to build a successful machine learning project. If you aspire to be a technical leader in AI, and know how to set direction for your team's work, this course will show you how. Much of this content has never been

Machine Learning - XII. Support Vector Machines (Week 7)

http://blog.csdn.net/pipisorry/article/details/44522881 机器学习Machine Learning - Andrew NG courses学习笔记 Support Vector Machines支持向量机 {SVM sometimes gives a cleaner and more powerful way of learning complex nonlinear functions} Optimization Objective优化目标

NTU-Coursera机器学习:机器学习基石 (Machine Learning Foundations)

课讲内容 这门课以8周设计,分成 4个核心问题,每个核心问题约需2周的时间来探讨.每个约2个小时的录影中,每个小时为一个主题,以会各分成4到5个小段落,每个段落里会有一个后多个随堂的练习.我们在探讨每个核心问题的第二周.依上所述,課程的規畫如下: When Can Machines Learn? [何时可以使用机器学习] 第一周:(NTU-Coursera机器学习:机器学习问题与二元分类) 第一讲:The Learning Problem [机器学习问题]第二讲:Learning to Answ

Teaching Your Computer To Play Super Mario Bros. – A Fork of the Google DeepMind Atari Machine Learning Project

Teaching Your Computer To Play Super Mario Bros. – A Fork of the Google DeepMind Atari Machine Learning Project Posted by ehrenbrav on August 25, 2016Leave a comment (14)Go to comments For those who want to get right to the good stuff, the installati

Machine Learning - Neural Networks Learning: Backpropagation in Practice

This series of articles are the study notes of " Machine Learning ", by Prof. Andrew Ng., Stanford University. This article is the notes of week 5, Neural Networks Learning. This article contains some topic about how to apply Backpropagation alg

机器学习算法之旅A Tour of Machine Learning Algorithms

In this post we take a tour of the most popular machine learning algorithms. It is useful to tour the main algorithms in the field to get a feeling of what methods are available. There are so many algorithms available and it can feel overwhelming whe

损失函数(Loss Function) -1

http://www.ics.uci.edu/~dramanan/teaching/ics273a_winter08/lectures/lecture14.pdf Loss Function 损失函数可以看做 误差部分(loss term) + 正则化部分(regularization term) 1.1 Loss Term Gold Standard (ideal case) Hinge (SVM, soft margin) Log (logistic regression, cross en