Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOLPHIN-94] Show both training/cross-validation error to check overfiting #95

Merged
merged 3 commits into from
Aug 30, 2015
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public final class NeuralNetworkTask implements Task {

private static final Logger LOG = Logger.getLogger(NeuralNetworkTask.class.getName());

private final Validator validator;
private final Validator crossValidator;
private final Validator trainingValidator;
private final DataParser<List<Pair<Pair<INDArray, Integer>, Boolean>>> dataParser;
private final NeuralNetwork neuralNetwork;
private final int maxIterations;
Expand Down Expand Up @@ -88,10 +89,17 @@ public void reset() {
/**
* @return the prediction accuracy of model.
*/
public float getStats() {
public float getAccuracy() {
return correctNum / (float) totalNum;
}

/**
* @return the prediction error of model.
*/
public float getError() {
return 1 - getAccuracy();
}

/**
* @return the total number of samples that are used for evaluation.
*/
Expand All @@ -103,13 +111,13 @@ public int getTotalNum() {
@Inject
NeuralNetworkTask(final DataParser<List<Pair<Pair<INDArray, Integer>, Boolean>>> dataParser,
final NeuralNetwork neuralNetwork,
@Parameter(MaxIterations.class) final int maxIterations,
final Validator validator) {
@Parameter(MaxIterations.class) final int maxIterations) {
super();
this.dataParser = dataParser;
this.neuralNetwork = neuralNetwork;
this.maxIterations = maxIterations;
this.validator = validator;
this.trainingValidator = new Validator(neuralNetwork);
this.crossValidator = new Validator(neuralNetwork);
}

/** {@inheritDoc} */
Expand All @@ -125,17 +133,20 @@ public byte[] call(final byte[] bytes) throws Exception {
final int label = data.getFirst().getSecond();
final boolean isValidation = data.getSecond();
if (isValidation) {
validator.validate(input, label);
crossValidator.validate(input, label);
} else {
neuralNetwork.train(input, label);
trainingValidator.validate(input, label);
}
}
LOG.log(Level.INFO, "=========================================================");
LOG.log(Level.INFO, "Iteration: {0}", String.valueOf(i));
LOG.log(Level.INFO, "Result: {0}", String.valueOf(validator.getStats()));
LOG.log(Level.INFO, "# of validation inputs: {0}", String.valueOf(validator.getTotalNum()));
LOG.log(Level.INFO, "Training Error: {0}", String.valueOf(trainingValidator.getError()));
LOG.log(Level.INFO, "Cross Validation Error: {0}", String.valueOf(crossValidator.getError()));
LOG.log(Level.INFO, "# of validation inputs: {0}", String.valueOf(crossValidator.getTotalNum()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a line that shows us the number of training inputs, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right!

LOG.log(Level.INFO, "=========================================================");
validator.reset();
crossValidator.reset();
trainingValidator.reset();
}

return null;
Expand Down