GithubHelp home page GithubHelp logo

neural-cli's Introduction

Command Line Neural Network

Neuralcli provides a simple command line interface to a python implementation of a simple classification neural network. Neuralcli allows a quick way and easy to get instant feedback on a hypothesis or to play around with one of the most popular concepts in machine learning today.

Installation

Installation of neuralcli is provided through pip, just run:

pip install neuralcli

If you don't have some of the libraries used, such as numpy or skitlearn the install make take some time as pip installs all the dependencies. After pip finishes the install run the following command -v neuralcli to check that the executable has been successfully added.

Troubleshooting

When you run neuralcli for the first time you may get an output similar to below

/usr/local/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')

This is just a warning from matplotlib, and will be removed the next time you run the command.

Additionally matlibplot may throw another error that will produce an output similar to:

**RuntimeError**: Python is not installed as a framework

To fix this issue follow the steps outlined here

Use

Neuralcli comes bundled with three main commands.

Train

The train command takes a set of input features along with their expected outputs and performs backpropogation to learn the weights for a neural network. These weights can be saved to an output file to use for classification prediction later. The command takes the following.

parameters:

name type description example
X file a file path to a CSV which holds your training data ./train.csv
Y file a file path to a CSV which holds your expected outputs for the training examples ./expected.csv

flags:

name type description default example
--lam float The regularization amount 1 0.07
--maxiter int The maximum iterations for chosen to minimise the cost function 250 30
--output string A file path to save the minimised parameters to nil ./output.csv
--normalize bool Perform normalization on the training set true false
--verbose bool Output the training progress true false

example:

$ neuralcli train ./X.csv ./Y.csv --output=./weights.csv --normalize=true

Once you run the train command the neural network will intialize and begin to learn the weights, you should see an output similar to bellow if the --verbose flag is set to true.

Predict

The prediction command takes a set of learned weights and a given input to predict a an ouput. The learned weights are loaded into the neural network by providing an file which holds them in a rolled 1 * n vector shape. In order for the predict command to work correctly these parameters need to be unrolled and therefore you need to provide the sizes of the input layer, hidden layer, and output labels that you wish to unroll the

parameters:

name type description example
x file the file that holds the 1 * n row example that should be predicted ./input.csv
params file The file that holds a 1 * n rolled parameter vector (saved from the train command) ./ouput.csv
labels int The size of the output layer that the parameters were trained on 3

flags:

name type description default example
--normalize bool Perform normalization on the training set true false
--sizeh int The size of the hidden layer if it differs from the input layer nil 8

example:

$ neuralcli predict ./x.csv 3 ./params.csv 

Neuralcli will now print a prediction in INT form, corresponding to the index of you output labels. e.g. 0 will correspond to you first classification label.

Test

The test command gives some primitive feedback about the correctness of your hypothesis by running a diagnostic check on the given data set and expected output. This method plots the the margin of prediction error against the increase in size of training examples. This can be useful to determine what is going wrong with your hypothesis, i.e. whether it is underfitting or overfitting the training set.

parameters:

name type description example
X file a file path to a CSV which holds your training data ./train.csv
Y file a file path to a CSV which holds your expected outputs for the training examples ./expected.csv

flags:

name type description default example
--lam float The regularization amount 1 0.07
--maxiter int The maximum iterations for chosen to minimise the cost function 250 30
--normalize bool Perform normalization on the training set true false
--verbose bool Output the training progress true false
--step int The increments that the training will increase the set by 10 100

example:

$ neuralcli train ./X.csv ./Y.csv --step=50 --normalize=true

Neural cli will then run the test sequence printing its progress as it increases the size of the training set.

After this runs it will then print a plot of the hypothesis error against the size of training set the weights where learned on. Below is an example graph plotted from the iris dataset.

neural-cli's People

Contributors

hugorut avatar wincentbalin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neural-cli's Issues

IndexError: index 1 is out of bounds for axis 0 with size 1

I tried to run neural-cli train ./x.csv ./y.csv --normalize=true --verbose=true with a simple set of training data and expected outputs, but I get the following error:

12.4131972238                    Traceback (most recent call last):
  File "/home/harri/Documents/neural-cli/bin/neuralcli", line 11, in <module>
    sys.exit(main())
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/neuralcli/cli.py", line 34, in train
    nn.train(verbose=verbose, save=output)
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/neuralcli/neuralnet.py", line 127, in train
    method='TNC', jac=True, options={'maxiter': self.maxiter})
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/scipy/optimize/_minimize.py", line 453, in minimize
    **options)
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/scipy/optimize/tnc.py", line 409, in _minimize_tnc
    xtol, pgtol, rescale, callback)
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/scipy/optimize/tnc.py", line 371, in func_and_grad
    f = fun(x, *args)
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/scipy/optimize/optimize.py", line 63, in __call__
    fg = self.fun(x, *args)
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/neuralcli/neuralnet.py", line 270, in fit
    yt = y[t,:]
  File "/home/harri/Documents/neural-cli/lib/python3.5/site-packages/numpy/matrixlib/defmatrix.py", line 318, in __getitem__
    out = N.ndarray.__getitem__(self, index)
IndexError: index 1 is out of bounds for axis 0 with size 1

The x.csv is like this:

a,b
1,1
1,2
1,3
1,4
1,5
2,1
2,2
2,3
2,4
2,5
2,6
3,1
3,2
3,3
3,4
3,5
3,6

And the y.csv is like this:

result
2
3
4
5
6
3
4
5
6
7
8
4
5
6
7
8
9

How the data should be in the .csv?

Hi, i wanted to try this and i couldn't because i don't know how should i create my data, could you please make a simple example in the README about a simple XOR by giving data.csv and guess.csv :)

Can this be used for image classification?

Hi,

I have a project where I'm taking a picture of the two counters on my electricity meter every 15 minutes.

I'm cropping out the individual digits and manipulate them until I have these: https://posted.bernieke.com/digit.jpg

I'd like to use neuralcli to train a network to classify these digits correctly.

I understand that I should have a Y.csv file with one row for each image in my training set, and 10 columns for my digits, with a 1 for the correct digit, and 0s for the others.

But how should I provide my images in the X.csv file?

Thank you,
Bernard

error after apparently successful install

Ubuntu 16.04, Python 3.5.2

Collecting neuralcli
Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/local/lib/python3.5/dist-packages (from neuralcli)
Requirement already satisfied (use --upgrade to upgrade): click in /usr/local/lib/python3.5/dist-packages (from neuralcli)
Requirement already satisfied (use --upgrade to upgrade): sklearn in /usr/local/lib/python3.5/dist-packages (from neuralcli)
Requirement already satisfied (use --upgrade to upgrade): scipy in /usr/local/lib/python3.5/dist-packages (from neuralcli)
Requirement already satisfied (use --upgrade to upgrade): matplotlib in /usr/lib/python3/dist-packages (from neuralcli)
Requirement already satisfied (use --upgrade to upgrade): scikit-learn in /usr/local/lib/python3.5/dist-packages (from sklearn->neuralcli)
Installing collected packages: neuralcli
Successfully installed neuralcli-1.2

fred@fred-XPS-L322X:~$ command -v neuralcli
/usr/local/bin/neuralcli
fred@fred-XPS-L322X:~$ which neuralcli
/usr/local/bin/neuralcli
fred@fred-XPS-L322X:~$ neuralcli
Traceback (most recent call last):
  File "/usr/local/bin/neuralcli", line 7, in <module>
    from neuralcli.cli import main
  File "/usr/local/lib/python3.5/dist-packages/neuralcli/cli.py", line 65
    print nn.predict(x)

xrange not defined

hi took your files and put it in d: folder
each i try i got a xrange not defined running python3.52 windows
it starts show some values after few seconsds crasdhed
installed with PIP
neuralcli train d:/neural/train.csv d:/neural/expected.csv --normalize=true
1.57867334226 Traceback (most recent call last):
File "c:\anaconda3\lib\runpy.py", line 184, in run_module_as_main
"main", mod_spec)
File "c:\anaconda3\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Anaconda3\Scripts\neuralcli.exe__main
.py", line 9, in
File "c:\anaconda3\lib\site-packages\click\core.py", line 716, in call
return self.main(_args, *_kwargs)
File "c:\anaconda3\lib\site-packages\click\core.py", line 696, in main
rv = self.invoke(ctx)
File "c:\anaconda3\lib\site-packages\click\core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\anaconda3\lib\site-packages\click\core.py", line 889, in invoke
return ctx.invoke(self.callback, *_ctx.params)
File "c:\anaconda3\lib\site-packages\click\core.py", line 534, in invoke
return callback(_args, **kwargs)
File "c:\anaconda3\lib\site-packages\neuralcli\cli.py", line 35, in train
nn.accuracy()
File "c:\anaconda3\lib\site-packages\neuralcli\neuralnet.py", line 318, in accuracy
for x in xrange(examples):
NameError: name 'xrange' is not defined

"Can't create weekday with n == 0" issue?

Hi there,

I tried to run neuralcli with an input CSV file with 10000 rows and 200 columns and an output of 10000 rows and 100 columns. I got the following issue-- not sure if it's on my end or a bug with the library itself.

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.4/bin/neuralcli", line 7, in <module> from neuralcli.cli import main File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/neuralcli/cli.py", line 2, in <module> from .neuralnet import NeuralNet File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/neuralcli/neuralnet.py", line 6, in <module> import matplotlib.pyplot as plt File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/pyplot.py", line 37, in <module> from matplotlib.figure import Figure, figaspect File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/figure.py", line 40, in <module> from matplotlib.axes import Axes, SubplotBase, subplot_class_factory File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/axes/__init__.py", line 4, in <module> from ._subplots import * File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/axes/_subplots.py", line 10, in <module> from matplotlib.axes._axes import Axes File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/axes/_axes.py", line 24, in <module> import matplotlib.dates as _ # <-registers a date unit converter File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/dates.py", line 125, in <module> from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/dateutil/rrule.py", line 55 raise ValueError, "Can't create weekday with n == 0"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.