Inspiration: Example from the Master Algorithm by Pedro Domingos
Just a Unix computer (Linux, ubuntu, macOS) with Python installed
git clone https://github.com/NervanaSystems/neon.git cd neon make . .venv/bin/activateAdditional instructions
import cPickle, numpy as np from neon.initializers import Uniform, Gaussian from neon.layers import GeneralizedCost, Affine from neon.models import Model from neon.optimizers import GradientDescentMomentum, Schedule from neon.transforms import Softmax, CrossEntropyMulti, SumSquared, Rectlin from neon.callbacks.callbacks import Callbacks from neon.data import ArrayIterator from neon.util.argparser import NeonArgparser from neon.transforms import Misclassification from numpy import genfromtxt parser = NeonArgparser(__doc__) args = parser.parse_args(gen_be=True)
X_data = genfromtxt("inputXOR.csv",delimiter=',') Y_data = genfromtxt("outputXOR.csv",delimiter=',',dtype=None) training_data = ArrayIterator(X=X_data[0:600], y=Y_data[0:600],nclass=2,make_onehot=True) test_data = ArrayIterator(X=X_data[600:800], y=Y_data[600:800],nclass=2,make_onehot=True)Download inputXOR.csv Download outputXOR.csv
ArrayIterator object returns one tuple(input,label) at a time
This iterator supports classification, regression, and autoencoder tasks
init = Gaussian() layers = [] layers.append(Affine(nout=2, init=init, bias=init, activation=Rectlin())) layers.append(Affine(nout=2, init=init, bias=init, activation=Softmax()))
mlp = Model(layers=layers)
No vanishing or exploding gradient problems
Cross validation with xoR data suggested Rectiliear function is most suitable
Other transformers - Identity, Explin, Normalizer,Tanh,Logistic
Softmax function enables probabilistic interpretation of output
Just like logistic function, the derivative of softmax function includes the inputs
cost = GeneralizedCost(costfunc=SumSquared())Other cost functions
optimizer = GradientDescentMomentum(0.1, momentum_coef=0.2) callbacks = Callbacks(mlp, eval_set=training_data, **args.callback_args)
mlp.fit(training_data, optimizer=optimizer, num_epochs=100, cost=cost,callbacks=callbacks)
results = mlp.get_outputs(test_data) prediction = results.argmax(1) print "Evaluating the model" error_pct = 100 * mlp.eval(test_data, metric=Misclassification()) print 'Misclassification error = %.1f%%' % error_pct np.savetxt("predictions.csv", prediction, delimiter=",") #downloads weights is required weights = mlp.get_description(get_weights=True) print mlp.get_description(True)['model']['config']['layers'][0]['params']['W'] print mlp.get_description(True)['model']['config']['layers'][1]['params']['W']
BTW, you might also like these previous posts
Intuition behind concept of gradient vector: https://t.co/vejnoSADmr #DataScience #MachineLearning by @pavanmirla pic.twitter.com/DKcX1p9X4m
— Kirk Borne (@KirkDBorne) July 17, 2016
Cool, colorful, creative → Perceptron Learning Algorithm in plain words https://t.co/LPmMTPsRHb #DataScience #MachineLearning by @pavanmirla
— Kirk Borne (@KirkDBorne) August 10, 2016
Maximum Likelihood Estimate (MLE) and Logistic Regression simplified: https://t.co/CUdOhpP4ko #DataScience #MachineLearning by @pavanmirla
— Kirk Borne (@KirkDBorne) July 25, 2016