Java Code Examples for org.neuroph.core.data.DataSet#createTrainingAndTestSubsets()
The following examples show how to use
org.neuroph.core.data.DataSet#createTrainingAndTestSubsets() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenerateData.java From NeurophFramework with Apache License 2.0 | 5 votes |
public void createTrainingAndTestSet() { //Creating data set from file DataSet dataSet = createDataSet(); dataSet.shuffle(); //Splitting main data set to training set (75%) and test set (25%) DataSet[] trainingAndTestSet = dataSet.createTrainingAndTestSubsets(75, 25); //Saving training set to file DataSet trainingSet = trainingAndTestSet[0]; System.out.println("Saving training set to file..."); trainingSet.save(config.getTrainingFileName()); System.out.println("Training set successfully saved!"); //Normalizing test set DataSet testSet = trainingAndTestSet[1]; System.out.println("Normalizing test set..."); Normalizer nor = new MaxNormalizer(trainingSet); nor.normalize(testSet); System.out.println("Saving normalized test set to file..."); testSet.shuffle(); testSet.save(config.getTestFileName()); System.out.println("Normalized test set successfully saved!"); System.out.println("Training set size: " + trainingSet.getRows().size() + " rows. "); System.out.println("Test set size: " + testSet.getRows().size() + " rows. "); System.out.println("-----------------------------------------------"); double percentTraining = (double) trainingSet.getRows().size() * 100.0 / (double) dataSet.getRows().size(); double percentTest = (double) testSet.getRows().size() * 100.0 / (double) dataSet.getRows().size(); System.out.println("Training set takes " + formatDecimalNumber(percentTraining) + "% of main data set. "); System.out.println("Test set takes " + formatDecimalNumber(percentTest) + "% of main data set. "); }
Example 2
Source File: GermanCreditDataSample.java From NeurophFramework with Apache License 2.0 | 4 votes |
public void run() { System.out.println("Creating training and test set from file..."); String dataSetFile = "data_sets/german credit data.txt"; int inputsCount = 24; int outputsCount = 2; //Create data set from file DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, " "); dataSet.shuffle(); //Normalizing data set Normalizer normalizer = new MaxNormalizer(dataSet); normalizer.normalize(dataSet); //Creatinig training set (70%) and test set (30%) DataSet[] trainingAndTestSet = dataSet.createTrainingAndTestSubsets(70, 30); DataSet trainingSet = trainingAndTestSet[0]; DataSet testSet = trainingAndTestSet[1]; System.out.println("Creating neural network..."); //Create MultiLayerPerceptron neural network MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 12, 6, outputsCount); //attach listener to learning rule MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule(); learningRule.addListener(this); learningRule.setLearningRate(0.01); learningRule.setMaxError(0.001); learningRule.setMaxIterations(10000); System.out.println("Training network..."); //train the network with training set neuralNet.learn(trainingSet); System.out.println("Testing network...\n\n"); testNeuralNetwork(neuralNet, testSet); System.out.println("Done."); System.out.println("**************************************************"); }
Example 3
Source File: IonosphereSample2.java From NeurophFramework with Apache License 2.0 | 4 votes |
public void run() { System.out.println("Creating training and test set from file..."); String dataSetFile = "data_sets/ionosphere.csv"; int inputsCount = 34; int outputsCount = 1; //Create data set from file DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, ","); dataSet.shuffle(); //Normalizing data set Normalizer normalizer = new MaxNormalizer(dataSet); normalizer.normalize(dataSet); //Creatinig training set (70%) and test set (30%) DataSet[] trainingAndTestSet = dataSet.createTrainingAndTestSubsets(70, 30); DataSet trainingSet = trainingAndTestSet[0]; DataSet testSet = trainingAndTestSet[1]; // ovde ubaci u petlju sa hidden neuronima i learning rates System.out.println("Creating neural network..."); //Create MultiLayerPerceptron neural network MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 10, 8, outputsCount); //attach listener to learning rule MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule(); learningRule.addListener(this); learningRule.setLearningRate(0.4); learningRule.setMaxError(0.01); learningRule.setMaxIterations(10000); System.out.println("Training network..."); //train the network with training set neuralNet.learn(trainingSet); // System.out.println("Testing network...\n\n"); // testNeuralNetwork(neuralNet, testSet); System.out.println("Done."); System.out.println("**************************************************"); // } }
Example 4
Source File: IonosphereSample.java From NeurophFramework with Apache License 2.0 | 4 votes |
public void run() { System.out.println("Creating training and test set from file..."); String dataSetFile = "data_sets/ionosphere.csv"; int inputsCount = 34; int outputsCount = 1; //Create data set from file DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, ","); dataSet.shuffle(); //Normalizing data set Normalizer normalizer = new MaxNormalizer(dataSet); normalizer.normalize(dataSet); //Creatinig training set (70%) and test set (30%) DataSet[] trainingAndTestSet = dataSet.createTrainingAndTestSubsets(70, 30); DataSet trainingSet = trainingAndTestSet[0]; DataSet testSet = trainingAndTestSet[1]; // for (int i = 0; i < 21; i++) { System.out.println("Creating neural network..."); //Create MultiLayerPerceptron neural network MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 16, 8, outputsCount); // System.out.println("HIDDEN COUNT: " + i); //attach listener to learning rule MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule(); learningRule.addListener(this); learningRule.setLearningRate(0.2); learningRule.setMaxError(0.01); learningRule.setMaxIterations(10000); System.out.println("Training network..."); //train the network with training set neuralNet.learn(trainingSet); System.out.println("Testing network...\n\n"); testNeuralNetwork(neuralNet, testSet); System.out.println("Done."); System.out.println("**************************************************"); // } }