本文整理汇总了Python中NeuralNetwork.NeuralNetwork.classify方法的典型用法代码示例。如果您正苦于以下问题:Python NeuralNetwork.classify方法的具体用法?Python NeuralNetwork.classify怎么用?Python NeuralNetwork.classify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NeuralNetwork.NeuralNetwork
的用法示例。
在下文中一共展示了NeuralNetwork.classify方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from NeuralNetwork import NeuralNetwork [as 别名]
# 或者: from NeuralNetwork.NeuralNetwork import classify [as 别名]
def test(base_directory, ignore_word_file, filtered, nb_hidden_neurons, nb_max_iteration):
print("post reading...")
pr = PostReader(base_directory, ignore_word_file, filtered)
print("creating neural network...")
nn = NeuralNetwork(pr.get_word_set(), nb_hidden_neurons, nb_max_iteration)
print("training...")
training_set = pr.get_training_set()
t0 = time.clock()
nb_iteration = nn.train(training_set)
training_time = time.clock() - t0
print("verification...")
t0 = time.clock()
verification_set = pr.get_verification_set()
verification_time = time.clock() - t0
nb_correct = 0
for msg in verification_set:
final = NeuralNetwork.threshold(nn.classify(msg[0]))
if final == msg[1]:
nb_correct += 1
print("=======================")
print("training set length : %s" % len(training_set))
print("nb hidden neurons : %s" % nb_hidden_neurons)
print("nb max iterations : %s" % nb_max_iteration)
print("nb iterations : %s" % nb_iteration)
print("verification set length: %s posts" % len(verification_set))
print("nb correct classified : %s posts" % nb_correct)
print("rate : %i %%" % (nb_correct / len(verification_set) * 100))
print("training time : %i s" % training_time)
print("verification time : %i s" % verification_time)
print("=======================")
print("")
示例2: NeuralNetworkTestcase
# 需要导入模块: from NeuralNetwork import NeuralNetwork [as 别名]
# 或者: from NeuralNetwork.NeuralNetwork import classify [as 别名]
class NeuralNetworkTestcase(unittest.TestCase):
def setUp(self):
self.nn = NeuralNetwork(['a', 'b'], 2)
self.nn.hidden_neurons[0].input_weights['a'] = 0.25
self.nn.hidden_neurons[0].input_weights['b'] = 0.50
self.nn.hidden_neurons[0].bias = 0.0
self.nn.hidden_neurons[1].input_weights['a'] = 0.75
self.nn.hidden_neurons[1].input_weights['b'] = 0.75
self.nn.hidden_neurons[1].bias = 0.0
self.nn.final_neuron.input_weights[0] = 0.5
self.nn.final_neuron.input_weights[1] = 0.5
self.nn.final_neuron.bias = 0.0
def test_calc(self):
self.nn.classify({'a': 1.0, 'b': 0.0})
self.assertAlmostEquals(self.nn.final_neuron.last_output, 0.650373, 5)
示例3: accuracy
# 需要导入模块: from NeuralNetwork import NeuralNetwork [as 别名]
# 或者: from NeuralNetwork.NeuralNetwork import classify [as 别名]
def accuracy(self, number_layers, numbers_neurons, learning_rate):
"""Returns the accuracy of a neural network associated with an Individual"""
net = NeuralNetwork(number_layers, numbers_neurons, learning_rate, X_train=self.dataset.X_train, Y_train=self.dataset.Y_train, X_test=self.dataset.X_test, Y_test=self.dataset.Y_test)
#train neural NeuralNetwork
net.train()
#calcule accurate
acc = net.classify()
#set AUC
self.__auc = net.get_auc()
return acc
示例4: NeuralNetworkXORTestcase
# 需要导入模块: from NeuralNetwork import NeuralNetwork [as 别名]
# 或者: from NeuralNetwork.NeuralNetwork import classify [as 别名]
class NeuralNetworkXORTestcase(unittest.TestCase):
def setUp(self):
self.nn = NeuralNetwork(['a', 'b'], 2)
self.nn.hidden_neurons[0].input_weights['a'] = 1.0
self.nn.hidden_neurons[0].input_weights['b'] = 1.0
self.nn.hidden_neurons[0].bias = 0.0
self.nn.hidden_neurons[1].input_weights['a'] = 1.0
self.nn.hidden_neurons[1].input_weights['b'] = 1.0
self.nn.hidden_neurons[1].bias = 0.0
self.nn.final_neuron.input_weights[0] = -1
self.nn.final_neuron.input_weights[1] = 1
self.nn.final_neuron.bias = 0.0
def test_classifiy(self):
self.assertAlmostEquals(self.nn.classify({'a': 1.0, 'b': 0.0}), 1.0, 5)
self.assertAlmostEquals(self.nn.classify({'a': 0.0, 'b': 1.0}), 1.0, 5)
self.assertAlmostEquals(self.nn.classify({'a': 1.0, 'b': 1.0}), 0.0, 5)
self.assertAlmostEquals(self.nn.classify({'a': 0.0, 'b': 0.0}), 0.0, 5)
def test_train(self):
self.nn = NeuralNetwork(['a', 'b'], 2)
self.nn.train([[{'a': 1.0, 'b': 0.0}, 1.0]])
self.nn.train([[{'a': 0.0, 'b': 1.0}, 1.0]])
self.nn.train([[{'a': 1.0, 'b': 0.0}, 1.0]])
self.nn.train([[{'a': 0.0, 'b': 1.0}, 1.0]])
self.nn.train([[{'a': 1.0, 'b': 0.0}, 1.0]])
self.nn.train([[{'a': 0.0, 'b': 1.0}, 1.0]])
self.nn.train([[{'a': 1.0, 'b': 0.0}, 1.0]])
self.nn.train([[{'a': 0.0, 'b': 1.0}, 1.0]])
self.assertAlmostEquals(self.nn.classify({'a': 1.0, 'b': 0.0}), 1.0, 5)
self.assertAlmostEquals(self.nn.classify({'a': 0.0, 'b': 1.0}), 1.0, 5)
self.assertAlmostEquals(self.nn.classify({'a': 1.0, 'b': 1.0}), 0.0, 5)
self.assertAlmostEquals(self.nn.classify({'a': 0.0, 'b': 0.0}), 0.0, 5)
self.nn.hidden_neurons[0].input_weights
示例5: main
# 需要导入模块: from NeuralNetwork import NeuralNetwork [as 别名]
# 或者: from NeuralNetwork.NeuralNetwork import classify [as 别名]
def main():
if len(sys.argv) != 3:
print "USAGE: python DigitClassifier" \
"<path_to_training_file> <path_to_testing_file>"
sys.exit(-1)
training_data = None
validation_data = None
testing_data = None
# load training file
print "Loading training data from '" + sys.argv[1] + "'..."
with open(sys.argv[1], 'rb') as f:
# skip headings
next(f)
X = []
Y = []
for line in f:
line = line.strip().split(',', 1)
Y.append(vectorize_digit(int(line[0])))
X.append(line[1].split(','))
# convert X into numpys float32 representation
X = np.array(X).astype(np.float32)
# normalize pixel values to lie between 0 - 1
# performance is very bad without normalization
X *= 1.0 / 255.0
X = [np.reshape(i, (784, 1)) for i in X]
# split point
N = int(len(X) * 0.2)
# split the data into 80-20
x = X[:N]
X = X[N:]
y = [de_vectorize(i) for i in Y[:N]]
Y = Y[N:]
training_data = zip(X, Y)
validation_data = zip(x, y)
print "Data Loaded."
print "Generating Neural Network..."
input_layer_neurons = 784
hidden_layer_neurons = [30]
output_layer_neurons = 10
epochs = 30
batch_size = 10
learning_rate = 3.0
net = NeuralNetwork([input_layer_neurons] +
hidden_layer_neurons + [output_layer_neurons])
print "Network Generated..."
print "\t Input Layer neuron count: " + str(input_layer_neurons)
print "\t Hidden Layer Count: " + str(len(hidden_layer_neurons))
for i in xrange(len(hidden_layer_neurons)):
print "\t\tHidden Layer " + str(i + 1) + " neuron count: "\
+ str(hidden_layer_neurons[i])
print "\t Output Layer neuron count: " + str(output_layer_neurons)
print "\nTraining for " + str(epochs) + " epochs..."
net.gradient_descent(training_data, epochs, batch_size,
learning_rate, validation_data)
# load training file
print "Loading testing data from '" + sys.argv[2] + "'..."
with open(sys.argv[2], 'rb') as f:
# skip headings
next(f)
X = []
for line in f:
X.append(line.split(','))
X = np.array(X).astype(np.float32)
X *= 1.0 / 255.0
X = [np.reshape(i, (784, 1)) for i in X]
testing_data = X
# get the classifier predictions
predictions = net.classify(testing_data)
print predictions
return