常用的损失函数
分类问题:交叉熵 (CE,Cross Entropy)
回归问题:均方根误差 (MSE,Mean Square Error)
以一个简单的例子实现自定义loss
假设某商品销售金额仅由变量x1和x2确定(y=x1+x2+噪声)
用到以下tf函数:
tf.where(条件,a,b) # 条件为真返回a,条件为假返回b
tf.greater(a,b) # 比大小,a>b 返回真,a<=b 返回假
代码:
import tensorflow as tf
import numpy as np
seed = 6
cost = 1
profit = 99
rdm = np.random.RandomState(seed)
x = rdm