Python实现第一个神经网络
2016-09-26 22:06
232 查看
步骤:
1、输入层、隐含层、输出层初始化
for item in range(10000):
l0=X
l1=nonlinear(np.dot(l0,syn0))
# how much did we miss?
l1_error=y-l1
# multiply how much we missed by the
# slope of the sigmoid at the values in l1
l1_delta=l1_error*nonlinear(l1,True)
#update weights
syn0=np.dot(l0.T,l1_delta)+syn0
’
3、其中要用到的激活函数有Sigmoid、tanh、ReLu、Leaky ReLU等,当然还需要求导公式进行梯度下降优化。
‘
def nonlinear(x,deriv=False):
if(deriv==True):
return x*(1-x)
return 1/(1+np.exp(-x))
’
1、输入层、隐含层、输出层初始化
X=np.array([[0,0,1], [0,1,1], [1,0,1], [0,1,1]]) y=np.array([[0,0,1,1]]).T np.random.seed(1) syn0=2*np.random.random((3,1))-1’ 2、前馈传递计算并计算误差率,通过BP算法进行迭代优化达到最小化损失函数
for item in range(10000):
l0=X
l1=nonlinear(np.dot(l0,syn0))
# how much did we miss?
l1_error=y-l1
# multiply how much we missed by the
# slope of the sigmoid at the values in l1
l1_delta=l1_error*nonlinear(l1,True)
#update weights
syn0=np.dot(l0.T,l1_delta)+syn0
’
3、其中要用到的激活函数有Sigmoid、tanh、ReLu、Leaky ReLU等,当然还需要求导公式进行梯度下降优化。
‘
def nonlinear(x,deriv=False):
if(deriv==True):
return x*(1-x)
return 1/(1+np.exp(-x))
’
相关文章推荐
- Python代码实现模拟退火算法Boltzman机神经网络权重调节
- 十一行Python代码实现一个神经网络(第一部分)
- 基于Python3 神经网络的实现
- 循环神经网络在Python 、Numpy和Theano中的实现
- 《神经网络与深度学习》第一章 使用神经网络来识别手写数字(三)- 用Python代码实现
- Deep Learning 学习笔记(二):神经网络Python实现
- 循环神经网络教程4-用Python和Theano实现GRU/LSTM RNN, Part 4 – Implementing a GRU/LSTM RNN with Python and Theano
- 使用python实现简单全连接神经网络
- 十一行Python代码实现一个神经网络(第一部分)
- 一个 11 行 Python 代码实现的神经网络
- 径向基(RBF)神经网络python实现
- Python 神经网络实现MNIST分类
- Python实现NN(神经网络)
- 6.2神经网络算法实现--python机器学习
- 神经网络python 实现
- python实现单隐层神经网络基本模型 推荐
- 一个 11 行 Python 代码实现的神经网络
- 集体智慧编程——神经网络预测点击率-Python实现
- 神经网络学习-python实现LSTM
- python实现简单神经网络算法