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

How do I import a CSV file #26

Closed davidrimshnick closed 6 years ago

davidrimshnick commented 6 years ago

Sorry I can't seem to find in the documentation...

jorgenkg commented 6 years ago

The library does not provide any means to import CSV files nor any other arbitrary file formats.

To import the CSV file content, you’ll have to use vanilla python code and read the file content. Eg:

with open(“file.csv”, “r”) as f:
   csv_content = f.read()
wizzwizz4 commented 6 years ago

Alternatively, you can make use of the csv module.

davidrimshnick commented 6 years ago

That's fine.. Maybe I am missing the documentation on how to convert these to "instances"? I don't see the documentation on how to create the instances other than hardcoding the data.

Really appreciate the library by the way!

On Mon, Apr 9, 2018 at 10:50 AM, wizzwizz4 notifications@github.com wrote:

Alternatively, you can make use of the csv https://docs.python.org/library/csv.html module.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jorgenkg/python-neural-network/issues/26#issuecomment-379779331, or mute the thread https://github.com/notifications/unsubscribe-auth/AELb3wCoPmWiOWr6BFgwVoGDANg_Lrwjks5tm3VBgaJpZM4TLREH .

wizzwizz4 commented 6 years ago

Can this be modified to do what you want?

csv_data = [[[0, 0], [0]], [[1, 0], [1]], [[0, 1], [1]], [[1, 1], [0]]]
dataset = [Instance(inputs, outputs) for (inputs, outputs) in csv_data]
davidrimshnick commented 6 years ago

I will try that, thank you.

On Mon, Apr 9, 2018 at 11:00 AM, wizzwizz4 notifications@github.com wrote:

Can this be modified to do what you want?

csv_data = [[[0, 0], [0]], [[1, 0], [1]], [[0, 1], [1]], [[1, 1], [0]]] dataset = [Instance(inputs, outputs) for (inputs, outputs) in csv_data]

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jorgenkg/python-neural-network/issues/26#issuecomment-379782769, or mute the thread https://github.com/notifications/unsubscribe-auth/AELb343IQg5vpOrGz1HCErMTyLc6CrD5ks5tm3eFgaJpZM4TLREH .