当前位置:网站首页>keras model.compile损失函数与优化器
keras model.compile损失函数与优化器
2020-11-06 01:22:00 【IT界的小小小学生】
损失函数
概述
损失函数是模型优化的目标,所以又叫目标函数、优化评分函数,在keras中,模型编译的参数loss指定了损失函数的类别,有两种指定方法:
model.compile(loss='mean_squared_error', optimizer='sgd')
或者
from keras import losses
model.compile(loss=losses.mean_squared_error, optimizer='sgd')
可用损失函数
可用的损失目标函数:
mean_squared_error或mse
mean_absolute_error或mae
mean_absolute_percentage_error或mape
mean_squared_logarithmic_error或msle
squared_hinge
hinge
categorical_hinge
binary_crossentropy(亦称作对数损失,logloss)
logcosh
categorical_crossentropy:亦称作多类的对数损失,注意使用该目标函数时,需要将标签转化为形如(nb_samples, nb_classes)的二值序列
sparse_categorical_crossentrop:如上,但接受稀疏标签。注意,使用该函数时仍然需要你的标签与输出值的维度相同,你可能需要在标签数据上增加一个维度:np.expand_dims(y,-1)
kullback_leibler_divergence:从预测值概率分布Q到真值概率分布P的信息增益,用以度量两个分布的差异.
poisson:即(predictions - targets * log(predictions))的均值
cosine_proximity:即预测值与真实标签的余弦距离平均值的相反数
损失函数公式
https://zhuanlan.zhihu.com/p/34667893
二分类-报错
关于损失函数的藏奸报错:
用Keras做文本二分类,总是遇到如题错误,
我的类别是0或1,但是错误跟我说不能是1.
参见:Received a label value of 1 which is outside the valid range of [0, 1) - Python, Keras
loss function的问题。
原来用的是sparse_categorical_crossentropy,
改为binary_crossentropy问题解决。
优化器
https://www.cnblogs.com/xiaobingqianrui/p/10756046.html

版权声明
本文为[IT界的小小小学生]所创,转载请带上原文链接,感谢
https://vip01.blog.csdn.net/article/details/95596549
边栏推荐
- 幽默:黑客式编程其实类似机器学习!
- (2)ASP.NET Core3.1 Ocelot路由
- 快快使用ModelArts,零基础小白也能玩转AI!
- (1)ASP.NET Core3.1 Ocelot介紹
- Network programming NiO: Bio and NiO
- Details of dapr implementing distributed stateful service
- 使用 Iceberg on Kubernetes 打造新一代云原生数据湖
- 你的财务报告该换个高级的套路了——财务分析驾驶舱
- Polkadot series (2) -- detailed explanation of mixed consensus
- Asp.Net Core learning notes: Introduction
猜你喜欢
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
通过深层神经网络生成音乐
hadoop 命令总结
如何将数据变成资产?吸引数据科学家
使用 Iceberg on Kubernetes 打造新一代云原生数据湖
向北京集结!OpenI/O 2020启智开发者大会进入倒计时
哇,ElasticSearch多字段权重排序居然可以这么玩
事半功倍:在没有机柜的情况下实现自动化
How to demote a domain controller in Windows Server 2012 and later
DRF JWT authentication module and self customization
随机推荐
Real time data synchronization scheme based on Flink SQL CDC
C language 100 question set 004 - statistics of the number of people of all ages
自然语言处理之命名实体识别-tanfordcorenlp-NER(一)
7.2.1 cache configuration of static resources
X Window System介紹
制造和新的自动化技术是什么?
恕我直言,我也是才知道ElasticSearch条件更新是这么玩的
遞迴思想的巧妙理解
The practice of the architecture of Internet public opinion system
Dapr實現分散式有狀態服務的細節
Menu permission control configuration of hub plug-in for azure Devops extension
被老程式設計師壓榨怎麼辦?我不想辭職
Asp.Net Core learning notes: Introduction
你的财务报告该换个高级的套路了——财务分析驾驶舱
如果前端不使用SPA又能怎样?- Hacker News
3分钟读懂Wi-Fi 6于Wi-Fi 5的优势
50 + open source projects are officially assembled, and millions of developers are voting
Analysis of ThreadLocal principle
Top 10 best big data analysis tools in 2020
03_ Detailed explanation and test of installation and configuration of Ubuntu Samba