Read a CSV file and do backpropogation with Encog
Code: "neural_net_encog1.py". Programming language: Python DMelt Version 1. Last modified: 10/25/2015. License: Pro
https://datamelt.org/code/cache/neural_net_encog1_7344.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



# Licensed under the Apache License, Version 2.0 (the "License");
# based on http://www.heatonresearch.com/encog/

"""
/**
 * XOR: This example is essentially the "Hello World" of neural network
 * programming. This example shows how to construct an Encog neural network to
 * predict the output from the XOR operator. This example uses resilient
 * propagation (RPROP) to train the neural network. RPROP is the best general
 * purpose supervised training method provided by Encog.
 * 
 * For the XOR example with RPROP I use 4 hidden neurons. XOR can get by on just
 * 2, but often the random numbers generated for the weights are not enough for
 * RPROP to actually find a solution. RPROP can have issues on really small
 * neural networks, but 4 neurons seems to work just fine.
 * 
 * This example reads the XOR data from a CSV file. This file should be
 * something like:
 * 
**/
"""

from org.encog import Encog
from org.encog.util.csv import CSVFormat
from org.encog.util.simple import EncogUtility,TrainingSetUtil 

# create data file
data="""
0,0,0
1,0,1
0,1,1
1,1,0
"""
name="test.csv"
fi=open(name, "w")
fi.write(data)
fi.close()

trainingSet=TrainingSetUtil.loadCSVTOMemory(CSVFormat.ENGLISH,name,False,2,1)
network=EncogUtility.simpleFeedForward(2,4,0,1,True)
EncogUtility.trainToError(network, trainingSet, 0.01)
EncogUtility.evaluate(network, trainingSet)
Encog.getInstance().shutdown()

Ads help maintain this website.