神经网络 tensorflow :损失函数
生活随笔
收集整理的這篇文章主要介紹了
神经网络 tensorflow :损失函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 基礎理論
- 交叉熵
- tensorFlow中的損失函數
- BinaryCrosstropy
- CategoricalCrossentropy
- CosineSimilarity
- Hinge
- Huber
- KLDivergence
- LogCosh
- MeanAbsoluteError
- MeanAbsolutePercentageError
- MeanSquaredError
- MeanSquaredLogarithmicError
- Poisson
- SquaredHinge
基礎理論
交叉熵
參考:https://zhuanlan.zhihu.com/p/35709485
常用于分類問題,但是也可以用于回歸問題
tensorFlow中的損失函數
BinaryCrosstropy
計算真實標簽和預測標簽之間的交叉熵損失。
當只有兩個標簽類別(假定為0和1)時,請使用此交叉熵損失。對于每個示例,每個預測應該有一個浮點值。
CategoricalCrossentropy
計算標簽和預測之間的交叉熵損失。
當有兩個或多個標簽類別時,請使用此交叉熵損失函數。我們希望標簽以one_hot表示形式提供。如果要以整數形式提供標簽,請使用SparseCategoricalCrossentropy損失。
CosineSimilarity
直接計算l2范數的差別
loss = -sum(l2_norm(y_true) * l2_norm(y_pred))
Hinge
loss = maximum(1 - y_true * y_pred, 0)
y_true = [[0., 1.], [0., 0.]] y_pred = [[0.6, 0.4], [0.4, 0.6]] # Using 'auto'/'sum_over_batch_size' reduction type. h = tf.keras.losses.Hinge() h(y_true, y_pred).numpy()Huber
結合了均方誤差和平均絕對值誤差
KLDivergence
相對熵
LogCosh
y_true = [[0., 1.], [0., 0.]] y_pred = [[1., 1.], [0., 0.]] # Using 'auto'/'sum_over_batch_size' reduction type. l = tf.keras.losses.LogCosh() l(y_true, y_pred).numpy()MeanAbsoluteError
y_true = [[0., 1.], [0., 0.]] y_pred = [[1., 1.], [1., 0.]] # Using 'auto'/'sum_over_batch_size' reduction type. mae = tf.keras.losses.MeanAbsoluteError() mae(y_true, y_pred).numpy()MeanAbsolutePercentageError
y_true = [[2., 1.], [2., 3.]] y_pred = [[1., 1.], [1., 0.]] # Using 'auto'/'sum_over_batch_size' reduction type. mape = tf.keras.losses.MeanAbsolutePercentageError() mape(y_true, y_pred).numpy()MeanSquaredError
y_true = [[0., 1.], [0., 0.]] y_pred = [[1., 1.], [1., 0.]] # Using 'auto'/'sum_over_batch_size' reduction type. mse = tf.keras.losses.MeanSquaredError() mse(y_true, y_pred).numpy()MeanSquaredLogarithmicError
y_true = [[0., 1.], [0., 0.]] y_pred = [[1., 1.], [1., 0.]] # Using 'auto'/'sum_over_batch_size' reduction type. msle = tf.keras.losses.MeanSquaredLogarithmicError() msle(y_true, y_pred).numpy()Poisson
y_true = [[0., 1.], [0., 0.]] y_pred = [[1., 1.], [0., 0.]] # Using 'auto'/'sum_over_batch_size' reduction type. p = tf.keras.losses.Poisson() p(y_true, y_pred).numpy()SquaredHinge
y_true = [[0., 1.], [0., 0.]] y_pred = [[0.6, 0.4], [0.4, 0.6]] # Using 'auto'/'sum_over_batch_size' reduction type. h = tf.keras.losses.SquaredHinge() h(y_true, y_pred).numpy()總結
以上是生活随笔為你收集整理的神经网络 tensorflow :损失函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 神经网络:激活函数
- 下一篇: 腾讯实习笔试:关于几个有序数组求交集的问