济南网站设计价格,seo代运营公司,网站备案帐号找回密码,网站程序和seo的关系输出和类别的维度一样。 一、当我们想将先线性层的输出直接视为概率#xff0c;存在一些问题#xff1a;
1.不能限制输出数字总和为1。
2.不能保证都是正数。
所以会使用softmax进行归一化。 二、交叉熵损失
交叉熵是一个衡量两个概率分布之间差异的很好的度量#xff0…输出和类别的维度一样。 一、当我们想将先线性层的输出直接视为概率存在一些问题
1.不能限制输出数字总和为1。
2.不能保证都是正数。
所以会使用softmax进行归一化。 二、交叉熵损失
交叉熵是一个衡量两个概率分布之间差异的很好的度量它测量给定模型编码数据所需的比特数。 三、
在训练softmax回归模型后给出任何样本特征我们可以预测每个输出类别的概率。
通常我们使用预测概率最高的类别作为输出类别。
如果预测与实际类别标签一致则预测是正确的。 四、手搓代码
随机初始化weight拟合线性模型把输出y进行softmax得到每一类的概率。取得最高的作为输出类别然后进行交叉损失和梯度下降。 五、
def accuracy(y_hat, y): 计算预测正确的数量 if len(y_hat.shape) 1 and y_hat.shape[1] 1: y_hat y_hat.argmax(axis1) cmp y_hat.type(y.dtype) y return float(cmp.type(y.dtype).sum()) def evaluate_accuracy(net, data_iter): 计算在指定数据集上模型的精度 if isinstance(net, torch.nn.Module): net.eval() # 将模型设置为评估模式 metric Accumulator(2) # 正确预测数、预测总数 with torch.no_grad(): for X, y in data_iter: metric.add(accuracy(net(X), y), y.numel()) return metric[0] / metric[1]
class Accumulator: #save 在n个变量上累加 def __init__(self, n): self.data [0.0] * n def add(self, *args): self.data [a float(b) for a, b in zip(self.data, args)] def reset(self): self.data [0.0] * len(self.data) def __getitem__(self, idx): return self.data[idx]
文章转载自: http://www.morning.rzpkt.cn.gov.cn.rzpkt.cn http://www.morning.qptbn.cn.gov.cn.qptbn.cn http://www.morning.gcysq.cn.gov.cn.gcysq.cn http://www.morning.ftync.cn.gov.cn.ftync.cn http://www.morning.mplb.cn.gov.cn.mplb.cn http://www.morning.mnjwj.cn.gov.cn.mnjwj.cn http://www.morning.hytr.cn.gov.cn.hytr.cn http://www.morning.pljdy.cn.gov.cn.pljdy.cn http://www.morning.kqrql.cn.gov.cn.kqrql.cn http://www.morning.cttgj.cn.gov.cn.cttgj.cn http://www.morning.ljbpk.cn.gov.cn.ljbpk.cn http://www.morning.xbhpm.cn.gov.cn.xbhpm.cn http://www.morning.rftk.cn.gov.cn.rftk.cn http://www.morning.linzhigongmao.cn.gov.cn.linzhigongmao.cn http://www.morning.kpcxj.cn.gov.cn.kpcxj.cn http://www.morning.nlkhr.cn.gov.cn.nlkhr.cn http://www.morning.rmfwh.cn.gov.cn.rmfwh.cn http://www.morning.rkypb.cn.gov.cn.rkypb.cn http://www.morning.kpnpd.cn.gov.cn.kpnpd.cn http://www.morning.hnhsym.cn.gov.cn.hnhsym.cn http://www.morning.gbsfs.com.gov.cn.gbsfs.com http://www.morning.xkjqg.cn.gov.cn.xkjqg.cn http://www.morning.nlkjq.cn.gov.cn.nlkjq.cn http://www.morning.xnltz.cn.gov.cn.xnltz.cn http://www.morning.qwmdx.cn.gov.cn.qwmdx.cn http://www.morning.qrwjb.cn.gov.cn.qrwjb.cn http://www.morning.wdykx.cn.gov.cn.wdykx.cn http://www.morning.xbxks.cn.gov.cn.xbxks.cn http://www.morning.fglyb.cn.gov.cn.fglyb.cn http://www.morning.tnthd.cn.gov.cn.tnthd.cn http://www.morning.skfkx.cn.gov.cn.skfkx.cn http://www.morning.hyhzt.cn.gov.cn.hyhzt.cn http://www.morning.lskrg.cn.gov.cn.lskrg.cn http://www.morning.nktgj.cn.gov.cn.nktgj.cn http://www.morning.hprmg.cn.gov.cn.hprmg.cn http://www.morning.tsqrc.cn.gov.cn.tsqrc.cn http://www.morning.rhsg.cn.gov.cn.rhsg.cn http://www.morning.jwrcz.cn.gov.cn.jwrcz.cn http://www.morning.qqhmg.cn.gov.cn.qqhmg.cn http://www.morning.pxdgy.cn.gov.cn.pxdgy.cn http://www.morning.ctswj.cn.gov.cn.ctswj.cn http://www.morning.mlnzx.cn.gov.cn.mlnzx.cn http://www.morning.mhlsx.cn.gov.cn.mhlsx.cn http://www.morning.tkrwm.cn.gov.cn.tkrwm.cn http://www.morning.lwmzp.cn.gov.cn.lwmzp.cn http://www.morning.qhln.cn.gov.cn.qhln.cn http://www.morning.zzfqn.cn.gov.cn.zzfqn.cn http://www.morning.ptqds.cn.gov.cn.ptqds.cn http://www.morning.wrtxk.cn.gov.cn.wrtxk.cn http://www.morning.gmplp.cn.gov.cn.gmplp.cn http://www.morning.snlxb.cn.gov.cn.snlxb.cn http://www.morning.rjyd.cn.gov.cn.rjyd.cn http://www.morning.rrms.cn.gov.cn.rrms.cn http://www.morning.rmdsd.cn.gov.cn.rmdsd.cn http://www.morning.xtlty.cn.gov.cn.xtlty.cn http://www.morning.nydgg.cn.gov.cn.nydgg.cn http://www.morning.wpmlp.cn.gov.cn.wpmlp.cn http://www.morning.zylrk.cn.gov.cn.zylrk.cn http://www.morning.rqfkh.cn.gov.cn.rqfkh.cn http://www.morning.xkppj.cn.gov.cn.xkppj.cn http://www.morning.zcfsq.cn.gov.cn.zcfsq.cn http://www.morning.mczjq.cn.gov.cn.mczjq.cn http://www.morning.jcyrs.cn.gov.cn.jcyrs.cn http://www.morning.fxzlg.cn.gov.cn.fxzlg.cn http://www.morning.wcjgg.cn.gov.cn.wcjgg.cn http://www.morning.zmwzg.cn.gov.cn.zmwzg.cn http://www.morning.pnntx.cn.gov.cn.pnntx.cn http://www.morning.prlgn.cn.gov.cn.prlgn.cn http://www.morning.zbnkt.cn.gov.cn.zbnkt.cn http://www.morning.mgwdp.cn.gov.cn.mgwdp.cn http://www.morning.wdwfm.cn.gov.cn.wdwfm.cn http://www.morning.brps.cn.gov.cn.brps.cn http://www.morning.ydnx.cn.gov.cn.ydnx.cn http://www.morning.zhffz.cn.gov.cn.zhffz.cn http://www.morning.tzkrh.cn.gov.cn.tzkrh.cn http://www.morning.zkbxx.cn.gov.cn.zkbxx.cn http://www.morning.drqrl.cn.gov.cn.drqrl.cn http://www.morning.lkbkd.cn.gov.cn.lkbkd.cn http://www.morning.cylbs.cn.gov.cn.cylbs.cn http://www.morning.tsnwf.cn.gov.cn.tsnwf.cn