(1)输入层到H1层的计算过程: h11 = sigmoid(11 + (-1)(-2) + 1) = 0.88 h12 = sigmoid(1*(-1) + (-1)1 + 0) = 0.27 H1层到H2层的计算过程: h21 = sigmoid(20.88 + (-2)*0.27 + 0) = 0.75 h22 = sigmoid((-1)*0.88 + (-1)0.27 + 0) = 0.29 H2层到输出层的计算过程: o1 = sigmoid(30.75 + (-1)*0.29 + (-2)) = 0.20 o2 = sigmoid((-1)0.75 + 40.29 + 2) = 0.88

对于PlayTennis的预测,朴素贝叶斯算法需要计算以下两个条件概率: P(PlayTennis=Yes|Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong) P(PlayTennis=No|Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong)

根据极大似然估计方法,这两个条件概率分别为: P(PlayTennis=Yes|Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong) = P(Outlook=sunny|PlayTennis=Yes) * P(Temperature=cool|PlayTennis=Yes) * P(Humidity=high|PlayTennis=Yes) * P(Wind=strong|PlayTennis=Yes) * P(PlayTennis=Yes) / P(Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong) = 2/9 * 1/3 * 3/9 * 3/9 * 9/14 / P(Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong) = 0.0154 / P(Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong)

P(PlayTennis=No|Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong) = P(Outlook=sunny|PlayTennis=No) * P(Temperature=cool|PlayTennis=No) * P(Humidity=high|PlayTennis=No) * P(Wind=strong|PlayTennis=No) * P(PlayTennis=No) / P(Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong) = 3/5 * 1/2 * 1/5 * 2/5 * 5/14 / P(Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong) = 0.0154 / P(Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong)

因为P(Outlook=sunny,Temperature=cool,Humidity=high,Wind=strong)对于两个条件概率都是相同的,所以只需要比较两个条件概率的大小即可得出预测结果。

(2)误差计算: 对于真实值(0.5,1),计算出预测值为(0.20,0.88),则误差为: E = (0.5-0.20)^2 + (1-0.88)^2 = 0.3056

调整网络参数: 为了使误差最小化,可以使用反向传播算法来调整网络参数。具体步骤如下:

  1. 计算输出层的误差项: δo1 = (y1-o1)o1(1-o1) = (0.5-0.20)0.20(1-0.20) = 0.120 δo2 = (y2-o2)o2(1-o2) = (1-0.88)0.88(1-0.88) = 0.098

  2. 计算H2层的误差项: δh21 = δo1wh211 h21*(1-h21) = 0.12030.75*(1-0.75) = 0.042 δh22 = δo2wh222 h22*(1-h22) = 0.09840.29*(1-0.29) = 0.029

  3. 根据误差项调整参数: H2层到输出层的参数调整: wh211 = wh211 + αδo1h21 = 3 + 0.50.1200.75 = 3.045 wh212 = wh212 + αδo2h21 = -1 + 0.50.0980.75 = -0.925 wh221 = wh221 + αδo1h22 = -1 + 0.50.1200.29 = -0.964 wh222 = wh222 + αδo2h22 = 4 + 0.50.0980.29 = 4.014 bh21 = bh21 + αδo1 = -2 + 0.50.120 = -1.940 bh22 = bh22 + αδo2 = 2 + 0.50.098 = 2.049

H1层到H2层的参数调整: wh111 = wh111 + αδh21h11 = 2 + 0.50.0420.88 = 2.018 wh112 = wh112 + αδh22h11 = -2 + 0.50.0290.88 = -1.973 wh121 = wh121 + αδh21h12 = -1 + 0.50.0420.27 = -1.017 wh122 = wh122 + αδh22h12 = -1 + 0.50.0290.27 = -0.992 bh11 = bh11 + αδh21 = 0 + 0.50.042 = 0.021 bh12 = bh12 + αδh22 = 0 + 0.50.029 = 0.015

其中,α表示学习率,一般设置在0.1-0.5之间

阅读如下神经网络结构图图中从左至右共有两个隐层H1、H2和一个输出层O每层都有两个节点激活函数为Sigmoid。1若输入为1-1给出各层正向输出的计算过程。图中输入层到H1层:wi11=1 wi12=-1 wi21=-2 wi22=1 bi1=1 bi2=0根据如下数据对Outlook=sunnyTemperature=coolHumidity=highWind=s

原文地址: https://www.cveoy.top/t/topic/cz5p 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录