Tensorflow误差计算

在这里插入图片描述

y=tf.constant([1,2,3,0,2])
y=tf.one_hot(y,depth=4)
y
<tf.Tensor: shape=(5, 4), dtype=float32, numpy=
array([[0., 1., 0., 0.],
       [0., 0., 1., 0.],
       [0., 0., 0., 1.],
       [1., 0., 0., 0.],
       [0., 0., 1., 0.]], dtype=float32)>
y=tf.cast(y,dtype=tf.float32)
out=tf.random.normal([5,4])
loss1=tf.reduce_mean(tf.square(y-out))
loss2=tf.square(tf.norm(y-out))/(5*4)
loss3=tf.reduce_mean(tf.losses.MSE(y,out))
loss1
<tf.Tensor: shape=(), dtype=float32, numpy=1.5393263>
loss2
<tf.Tensor: shape=(), dtype=float32, numpy=1.5393263>
loss3
<tf.Tensor: shape=(), dtype=float32, numpy=1.5393263>


在这里插入图片描述

p=tf.fill([4],0.25)
entropy=-tf.reduce_sum(p*tf.math.log(p)/tf.math.log(2.))
entropy
<tf.Tensor: shape=(), dtype=float32, numpy=2.0>

在这里插入图片描述
交叉熵越小越好:
分类问题求解:

tf.losses.categorical_crossentropy([0,1,0,0],[0.25,0.25,0.25,0.25],from_logits=True)
<tf.Tensor: shape=(), dtype=float32, numpy=1.3862944>
tf.losses.categorical_crossentropy([0,1,0,0],[0.1,0.7,0.1,0.1],from_logits=True)
<tf.Tensor: shape=(), dtype=float32, numpy= numpy=0.97321343>

sigmoid函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值