jorgenkg / python-neural-network

This is an efficient implementation of a fully connected neural network in NumPy. The network can be trained by a variety of learning algorithms: backpropagation, resilient backpropagation and scaled conjugate gradient learning. The network has been developed with PYPY in mind.
BSD 2-Clause "Simplified" License
297 stars 98 forks source link

Can't figure out how to use with csv files/numpy arrays. #11

Closed yasiemir closed 8 years ago

jorgenkg commented 8 years ago

If you provide an example piece of code, I'll help you modify it. Untill then, maybe you answer will be resolved through a quick scroll on this page: nimblenet?

yasiemir commented 8 years ago

I was trying to use neural net with following settings

settings = {
    "n_inputs":784,
    "layers":[(25,'sigmoid_function'),(25,'sigmoid_function'),(10,'sigmoid_function') ]
}
new_network = NeuralNet(settings)
cost_function = 'sigmoid_function'
network = NeuralNet(settings)

I want to train this data from a csv file which i have imported as follows

training_data = pd.read_csv('train.csv')
X = training_data.iloc[:,1:].values
y = training_data.iloc[:,0].values

where X is 28000x784 feature matrix and y is 28000x10 label matrix

Now I can't figure out how to use it with preprocessing function

This dosn't seem to work

dataset = [Instance(X,y)]
#preprocessor        = construct_preprocessor( dataset, [replace_nan, standarize] )
#training_data       = preprocessor( dataset )

How can I train the neural network on X and y?

jorgenkg commented 8 years ago

I'm guessing pd.read_csv is a method from the pandas library? And further that

input_matrix = pd.read_csv('train.csv').iloc[:,1:].values
#input_matrix has shape (n_samples, n_features)

The issue arises where you initalize a single training instance with the entire training set:

dataset = [ Instance( input_matrix, y )] # input_matrix = pd.read_csv('train.csv').iloc[:,1:].values

You have to loop over the instances in the input_matrix and initialize one Instance for each input vector. The correct syntax is: Instance( input_vector, target_vector )

jorgenkg commented 8 years ago

Let me know if it didn't work out