Maschine learning #4

import numpy as np


#step 1 Collect Data
x = np.array([[0,0,1],
              [0,1,1],
              [1,0,1],
              [1,1,1]])
print(x)                      #x value and y value

y = np.array([[0],
              [1],
              [1],
              
              [0]])
print (y)


num_epochs = 60000
print(data_epoches)

#initialize weights
syn0 = 2*np.random.random((3,4))-1
syn1 = 2*np.random.random((4,1))-1                         #given test data 60000 and weight


#soid function

def nonline(x,deriv=False):
    if (deriv==True):
        return x*(1-x)
    else:
        return 1/(1+np.exp(-x))


#Step3 Train Model
for j in range(num_epochs):
    #feed forward through layers 0,1 and 2
    k0 = x
    k1 = nonline(np.dot(k0,syn0))
    k2 = nonline(np.dot(k1,syn1))
   

#backpropagation

    #how much did we miss the target value?
    
    k2_error = y-k2
    
    if(j%10000) == 0:
        print ("Error" + str(np.mean(np.abs(k2_error))))
    
    #in what direction is the target value?
    k2_delta = k2_error * nonline(k2,deriv=True)
    
    
    #how much did each k1  value contribute to k2 error
    k1_error = k2_delta.dot(syn1.T)
    k1_delta= k1_error*nonline(k1,deriv=True)
    
    syn1 += k1.T.dot(k2_delta)
    syn0 += k0.T.dot(k1_delta)
   

  






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值