Usage of loss functions
来源:互联网 发布:js 上传文件的原理 编辑:程序博客网 时间:2024/06/03 19:47
转自:https://keras.io/losses/
A loss function (or objective function, or optimization score function) is one of the two parameters required to compile a model:
model.compile(loss='mean_squared_error', optimizer='sgd')
from keras import lossesmodel.compile(loss=losses.mean_squared_error, optimizer='sgd')
You can either pass the name of an existing loss function, or pass a TensorFlow/Theano symbolic function that returns a scalar for each data-point and takes the following two arguments:
- y_true: True labels. TensorFlow/Theano tensor.
- y_pred: Predictions. TensorFlow/Theano tensor of the same shape as y_true.
The actual optimized objective is the mean of the output array across all datapoints.
For a few examples of such functions, check out the losses source.
Available loss functions
mean_squared_error
mean_squared_error(y_true, y_pred)
mean_absolute_error
mean_absolute_error(y_true, y_pred)
mean_absolute_percentage_error
mean_absolute_percentage_error(y_true, y_pred)
mean_squared_logarithmic_error
mean_squared_logarithmic_error(y_true, y_pred)
squared_hinge
squared_hinge(y_true, y_pred)
hinge
hinge(y_true, y_pred)
categorical_crossentropy
categorical_crossentropy(y_true, y_pred)
sparse_categorical_crossentropy
sparse_categorical_crossentropy(y_true, y_pred)
binary_crossentropy
binary_crossentropy(y_true, y_pred)
kullback_leibler_divergence
kullback_leibler_divergence(y_true, y_pred)
poisson
poisson(y_true, y_pred)
cosine_proximity
cosine_proximity(y_true, y_pred)
Note: when using the categorical_crossentropy
loss, your targets should be in categorical format (e.g. if you have 10 classes, the target for each sample should be a 10-dimensional vector that is all-zeros expect for a 1 at the index corresponding to the class of the sample). In order to convert integer targets into categorical targets, you can use the Keras utility to_categorical
:
from keras.utils.np_utils import to_categoricalcategorical_labels = to_categorical(int_labels, num_classes=None)
- Usage of loss functions
- loss functions for NN
- Face recognition-Loss Functions
- KERAS: objective or loss functions
- Surrogate Loss Functions in Machine Learning
- CS231N-Lecture3 Loss Functions and Optimization
- Usage of Pseudocode
- Usage of MFC CRectTracker
- Usage of awk
- effective usage of strtok
- Usage of Protocol Buffer
- Usage of pmake
- Usage sample of SSL
- usage of >>>、>> and << operators
- Extensive usage of Make
- Usage of Oracle Block
- Usage of TKPROF
- Usage of Ftp
- MySQL数据类型
- .write()与innerHTML的区别
- HDU 2066 最简单的Dijkstra算法实例
- linux之目录结构
- javaScript的数组队列操作
- Usage of loss functions
- Shader编程学习笔记(五)—— Fixed Function Shader 1
- MySQL
- hadoop初识
- 记广东公共交通大数据竞赛—— 公交线路客流预测
- HDU
- 从Oracle RAC角度看跨数据中心的存储双活配置注意事项
- 归并排序
- PHP mysqli 操作数据库