In [13]:
#Example with a Classifier using the scikit-learn library
#example for the XOr gate
from sklearn.neural_network import MLPClassifier

In [8]:
X = [[0., 0.],[0., 1.], [1., 0.], [1., 1.]] # each one of the entries 00 01 10 11
y = [0, 1, 1, 0] # outputs for each one of the entries
clf = MLPClassifier(algorithm='l-bfgs', alpha=1e-5, hidden_layer_sizes=(10), random_state=1, verbose=True, max_iter=1000)
clf.fit(X, y)


Out[8]:
MLPClassifier(activation='relu', algorithm='l-bfgs', alpha=1e-05,
       batch_size='auto', beta_1=0.9, beta_2=0.999, early_stopping=False,
       epsilon=1e-08, hidden_layer_sizes=10, learning_rate='constant',
       learning_rate_init=0.001, max_iter=1000, momentum=0.9,
       nesterovs_momentum=True, power_t=0.5, random_state=1, shuffle=True,
       tol=0.0001, validation_fraction=0.1, verbose=True, warm_start=False)

In [11]:
outp =  clf.predict([[0., 0.],[0., 1.], [1., 0.], [1., 1.]])




In [12]:
print'Results:'
print '0 0:', outp[0]
print '0 1:', outp[1]
print '1 0:', outp[2]
print '1 1:', outp[0]
print'Score:', clf.score(X, y)


Results:
0 0: 0
0 1: 1
1 0: 1
1 1: 0
Score: 1.0

In [ ]: