public virtual void run() { Console.WriteLine("Creating training and test set from file..."); string trainingSetFileName = "data_sets/segment challenge.txt"; string testSetFileName = "data_sets/segment test.txt"; int inputsCount = 19; int outputsCount = 7; //Create training data set from file DataSet trainingSet = DataSet.createFromFile(trainingSetFileName, inputsCount, outputsCount, ","); Console.WriteLine("Training set size: " + trainingSet.Rows.Count); trainingSet.shuffle(); trainingSet.shuffle(); //Normalizing training data set Normalizer normalizer = new MaxNormalizer(); normalizer.normalize(trainingSet); //Create test data set from file DataSet testSet = DataSet.createFromFile(testSetFileName, inputsCount, outputsCount, ","); Console.WriteLine("Test set size: " + testSet.Rows.Count); Console.WriteLine("--------------------------------------------------"); testSet.shuffle(); testSet.shuffle(); //Normalizing training data set normalizer.normalize(testSet); Console.WriteLine("Creating neural network..."); //Create MultiLayerPerceptron neural network MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 17, 10, outputsCount); //attach listener to learning rule MomentumBackpropagation learningRule = (MomentumBackpropagation)neuralNet.LearningRule; learningRule.addListener(this); learningRule.LearningRate = 0.01; learningRule.MaxError = 0.001; learningRule.MaxIterations = 12000; Console.WriteLine("Training network..."); //train the network with training set neuralNet.learn(trainingSet); Console.WriteLine("Testing network...\n\n"); testNeuralNetwork(neuralNet, testSet); Console.WriteLine("Done."); Console.WriteLine("**************************************************"); // } }
public virtual void normalizeBalancedTrainingSet() { //Normalizing balanced training set with MaxNormalizer DataSet dataSet = DataSet.load(config.BalancedFileName); Normalizer normalizer = new MaxNormalizer(); normalizer.normalize(dataSet); Console.WriteLine("Saving normalized training data set to file... "); dataSet.shuffle(); dataSet.shuffle(); dataSet.save(config.NormalizedBalancedFileName); Console.WriteLine("Normalized training data set successfully saved!"); }
public virtual void run() { Console.WriteLine("Creating training and test set from file..."); string trainingSetFileName = "data_sets/diabetes.txt"; int inputsCount = 8; int outputsCount = 2; //Create data set from file DataSet dataSet = DataSet.createFromFile(trainingSetFileName, inputsCount, outputsCount, ","); dataSet.shuffle(); //Normalizing data set Normalizer normalizer = new MaxNormalizer(); 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++) { Console.WriteLine("Creating neural network..."); //Create MultiLayerPerceptron neural network MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 9, outputsCount); // System.out.println("HIDDEN COUNT: " + i); //attach listener to learning rule MomentumBackpropagation learningRule = (MomentumBackpropagation)neuralNet.LearningRule; learningRule.addListener(this); learningRule.LearningRate = 0.05; learningRule.MaxError = 0.01; learningRule.MaxIterations = 10000; Console.WriteLine("Training network..."); //train the network with training set neuralNet.learn(trainingSet); Console.WriteLine("Testing network...\n\n"); testNeuralNetwork(neuralNet, testSet); Console.WriteLine("Done."); Console.WriteLine("**************************************************"); // } }
public virtual void run() { Console.WriteLine("Creating training set..."); string trainingSetFileName = "data_sets/cpu_data.txt"; int inputsCount = 7; int outputsCount = 1; // create training set from file DataSet dataSet = DataSet.createFromFile(trainingSetFileName, inputsCount, outputsCount, ",", false); Normalizer normalizer = new MaxNormalizer(); normalizer.normalize(dataSet); Console.WriteLine("Creating neural network..."); // create MultiLayerPerceptron neural network MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 16, outputsCount); // attach listener to learning rule MomentumBackpropagation learningRule = (MomentumBackpropagation)neuralNet.LearningRule; learningRule.addListener(this); // set learning rate and max error learningRule.LearningRate = 0.2; learningRule.MaxError = 0.01; Console.WriteLine("Training network..."); // train the network with training set neuralNet.learn(dataSet); Console.WriteLine("Training completed."); Console.WriteLine("Testing network..."); testNeuralNetwork(neuralNet, dataSet); Console.WriteLine("Saving network"); // save neural network to file neuralNet.save("MyNeuralNetCPU.nnet"); Console.WriteLine("Done."); }
public virtual 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]; Console.WriteLine("Saving training set to file..."); trainingSet.save(config.TrainingFileName); Console.WriteLine("Training set successfully saved!"); //Normalizing test set DataSet testSet = trainingAndTestSet[1]; Console.WriteLine("Normalizing test set..."); Normalizer nor = new MaxNormalizer(); nor.normalize(testSet); Console.WriteLine("Saving normalized test set to file..."); testSet.shuffle(); testSet.save(config.TestFileName); Console.WriteLine("Normalized test set successfully saved!"); Console.WriteLine("Training set size: " + trainingSet.Rows.Count + " rows. "); Console.WriteLine("Test set size: " + testSet.Rows.Count + " rows. "); Console.WriteLine("-----------------------------------------------"); double percentTraining = (double)trainingSet.Rows.Count * 100.0 / (double)dataSet.Rows.Count; double percentTest = (double)testSet.Rows.Count * 100.0 / (double)dataSet.Rows.Count; Console.WriteLine("Training set takes " + formatDecimalNumber(percentTraining) + "% of main data set. "); Console.WriteLine("Test set takes " + formatDecimalNumber(percentTest) + "% of main data set. "); }