试图通过神经网络前向传播一些数据
import numpy as np
import matplotlib.pyplot as plt
class Neural_Network(object):
def __init__(self):
#Define Hyperparameters
self.inputLayerSize = 2
self.outputLayerSize = 1
self.hiddenLayerSize = 3
#Weights (parameters)
self.W1 = np.random.randn(self.inputLayerSize, self.hiddenLayerSize)
self.W2 = np.random.randn(self.hiddenLayerSize, self.outputLayerSize)
def forward(self, X):
#Propagate inputs though network
self.z2 = np.dot(X, self.W1)
self.a2 = self.sigmoid(self.z2)
self.z3 = np.dot(self.a2, self.W2)
yHat = self.sigmoid(self.z3)
return yHat
def sigmoid(z):
# apply sigmoid activation function
return 1/(1+np.exp(-z))
当我运行时:
NN = Neural_Network()
yHat = NN.forward(X)
为什么我会收到错误消息:TypeError: sigmoid() takes exactly 1 argument (2 given)
当我运行时:
print NN.W1
我得到:[[ 1.034435 -0.19260378 -2.73767483]
[-0.66502157 0.86653985 -1.22692781]]
(也许这是 numpy dot 函数返回太多维度的问题?)
*注意:我在 jupyter notebook 中运行,并且%pylab inline