Skip to content

Instantly share code, notes, and snippets.

@mertyildiran
Created April 4, 2016 21:48
Show Gist options
  • Save mertyildiran/47c535998c327ae501876a293f0e8a90 to your computer and use it in GitHub Desktop.
Save mertyildiran/47c535998c327ae501876a293f0e8a90 to your computer and use it in GitHub Desktop.
Basic Neural Network example with PyBrain
from pybrain.tools.shortcuts import buildNetwork
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer
net = buildNetwork(3, 1, 1, bias=False)
ds = SupervisedDataSet(3, 1)
ds.addSample((0, 0, 1), (1,))
ds.addSample((0, 1, 1), (1,))
ds.addSample((1, 0, 1), (1,))
ds.addSample((1, 1, 0), (0,))
trainer = BackpropTrainer(net, ds)
trainer.trainUntilConvergence()
print net.activate([0, 0, 1])
print net.activate([0, 1, 1])
print net.activate([1, 0, 1])
print net.activate([1, 1, 0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment