python:logistic,softmax函数
来源:互联网 发布:jquery post 返回json 编辑:程序博客网 时间:2024/05/23 21:37
在学习时,经常会遇到分类的问题,简单的讲:分类就是设定一个阈值,将你想分类的对象与这个阈值进行比较,根据结果来进行决定分类。
最简单的分类函数是阶跃函数(简单粗暴)
但问题在于,这模型不够光滑,阶跃点从0到1突变,阶跃点难以处理,分类的效果也就那样。
logistic函数:一种常见的S形函数,它是皮埃尔·弗朗索瓦·韦吕勒在1844或1845年在研究它与人口增长的关系时命名的。(生物课上经常看到)
公式为:
logistic函数的优点:
够光滑,取值从-∞到∞,而且每一点的导数都存在
python实现:
import numpy as npimport matplotlib.pyplot as pltdef logistic(x): return 1/(1+np.exp(-x))x=np.arange(-6.0,6.0,0.1)plt.plot(x,logistic(x).T,linewidth=2)plt.show()
结果:
softmax函数:
本质是将一个K维的任意实数向量压缩(映射)成另一个K维的实数向量,其中向量中的每个元素取值都介于(0,1)之间。
与logistic函数不同的是,logistic函数主要解决的是二分类问题,而softmax函数主要解决的是多分类问题
softmax函数公式:
python代码:
import numpy as npimport matplotlib.pyplot as pltdef softmax(x): return np.exp(x)/np.sum(np.exp(x),axis=0)x=np.arange(-2.0,6.0,0.1)scores=np.stack([x,np.ones_like(x),0.2*np.ones_like(x)])plt.plot(x,softmax(scores).T,linewidth=2)plt.show()
结果:
logistic函数与softmax函数的区别:
softmax建模使用的分布是多项式分布,而logistic则基于伯努利分布,
伯努利分布是一种离散分布,有两种可能的结果1和0。
多项式分布是二项分布的推广,有不止二种结果
softmax回归和多个logistic回归的关系:
softmax回归进行的多分类,类与类之间是互斥的,即一个输入只能被归为一类;
多个logistic回归进行多分类,输出的类别并不是互斥的,即”苹果”这个词语既属于”水果”类也属于”3C”类别。
相关博客:
logistic函数和softmax函数
阅读全文
0 0
- python:logistic,softmax函数
- logistic函数和softmax函数
- logistic函数和softmax函数
- [Machine Learning] logistic函数和softmax函数
- logistic分类函数和softmax分类函数
- 【优化】logistic和softmax代价函数
- Logistic & softmax
- logistic函数是softmax函数的一个特例
- logistic regression 和 softmax regression的损失函数
- Logistic Regression & softmax
- logistic regress and softmax
- softmax 与 logistic Regression
- softmax logistic loss详解
- Softmax loss, softmax, multinominal and logistic loss
- Softmax Regression and Logistic Regression
- logistic和softmax原理、联系
- logistic回归和softmax回归
- Softmax回归与Logistic回归
- Struts :Exception starting filter struts2
- further occurrences of HTTP header parsing errors will be logged at DEBUG level.错误
- 洛谷P2831 [Noip2016]愤怒的小鸟
- Python报错TypeError: 'str' object is not callable
- OpenCV实现膨胀与腐蚀
- python:logistic,softmax函数
- AC自动机
- 浏览器缓存详解:expires,cache-control,last-modified,etag详细说明
- 【剑指offer】面试题61:扑克牌中的顺子
- 使用Oracle VM VirtualBox安装Ubuntu14.04.5并安装jdk,tomcat
- iOS 图片处理-图片旋转和裁剪
- How to solve laptop
- jxl导入/导出excel(转)
- ListView:在Adapter中修改item里的某个图形的大小、填充颜色、边距