ml-class /

#!/usr/bin/env python

from import buildNetwork
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import BackpropTrainer
from import loadmat
from itertools import izip

data = loadmat('ex3/ex3data1.mat')
X, y = data['X'], data['y']
ds = SupervisedDataSet(X.shape[1], y.shape[1])
for inp, target in izip(X, y):
    ds.addSample(inp, target)

net = buildNetwork(X.shape[1], X.shape[1], y.shape[1])
t = BackpropTrainer(net, learningrate=0.01,momentum=0.5)
t.trainOnDataset(ds, 10)

from random import choice
indexes = range(len(X))
for _ in range(10):
    i = choice(indexes)
    print(net.activate(X[i]), y[i])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.