私はTariq Rashidの "自分のニューラルネットワークを作成する"から次のコードを直接実行しています。それは "NameError:name 'self'は定義されていません。しかしそれは定義されています。コードは本からまっすぐです。NameError:名前 'self'はニューラルネットワークの例では定義されていません
import numpy
#neural network class definition
class neuralNetwork:
#initialize the neural network
def __init__(self, inputnodes, hiddennodes, outputnodes, learningrate):
# set number of nodes in each input, hidden, output layer
self.inodes = inputnodes
self.hnodes = hiddennodes
self.onodes = outputnodes
#learning rate
self.lr = learningrate
pass
#train the neural network
def train():
pass
#query the neural network
def query():
pass
#number of input, hidden and output nodes
input_nodes = 3
hidden_nodes = 3
output_nodes = 3
#learning rate is 0.3
learning_rate = 0.3
#create instance of neural network
n = neuralNetwork(input_nodes, hidden_nodes, output_nodes, learning_rate)
numpy.random.rand(3, 3)-0.5
#link weight matrices, wih and who
#weights inside the arrays are w_i_j, where link is from node i to node j in
the next layer
#w11 w21
#w12 w22 etc
self.wih = (numpy.random.rand(self.hnodes, self.inodes) - 0.5)
self.who = (numpy.random.rand(self.onodes, self.hnodes) - 0.5)
交換してください。 '' 'self.wih =(num.h.jar、self.node) - 0.5) self.who =(numpy.random.rand(self.onodes、self.hnodes) - 0.5)' '' 'WIH =(numpy.random.rand(n.hnodes、n.inodes) - 0.5)と 者=(numpy.random.rand(n.onodes、n.hnあなたが文法エラーなしで適切な答えを与える – Jithin