Xavier Peña
Xavier Peña

Reputation: 7919

How to calculate the "training dataset error" in Encog Machine Learning Framework

I am using CalculateGradients() (source) on a test dataset (30% of my data). See code below.

The goal is to get the error on the testingDataSet, using the parameters calculated by trainingDataSet (70% of my data).

My question: is CalculateGradients() independent? (thus just allowing me to calculate the error as intended), or is it adding another iteration to the shared network thus spoiling the isolation of the "training dataset"?

Source code for Iteration() here: source.

Code:

public void Train(BasicNetwork network, IMLDataSet trainingDataSet, IMLDataSet testingDataSet)
{
    var trainPropagation = new ResilientPropagation(network, trainingDataSet);
    var testPropagation = new ResilientPropagation(network, testingDataSet);

    var epoch = 1;
    do
    {
        trainPropagation.Iteration();

        // !!! Trying to calculate the error on `testingDataSet` using the parameters from `trainPropagation`
        testPropagation.CalculateGradients();

        Console.WriteLine($"Epoch #{epoch}, Train error: {trainPropagation.Error}, Test error: {testPropagation.Error}" );

        if (double.IsNaN(trainPropagation.Error))
            throw new Exception("Train error was NaN");                

        epoch++;

    } while (trainPropagation.Error > _maxError);

}

Upvotes: 1

Views: 127

Answers (0)

Related Questions