public boolean executeCommand(final String args) {
setKfold( obtainCross() );
final MLDataSet trainingSet = obtainTrainingSet();
MLMethod method = obtainMethod();
final MLTrain trainer = createTrainer(method, trainingSet);
if( method instanceof BayesianNetwork ) {
final String query = getProp().getPropertyString(
ScriptProperties.ML_CONFIG_QUERY);
((BayesianNetwork)method).defineClassificationStructure(query);
}
EncogLogging.log(EncogLogging.LEVEL_DEBUG, "Beginning training");
performTraining(trainer, method, trainingSet);
final String resourceID = getProp().getPropertyString(
ScriptProperties.ML_CONFIG_MACHINE_LEARNING_FILE);
final File resourceFile = getAnalyst().getScript().resolveFilename(
resourceID);
// reload the method
method = null;
if( trainer instanceof EvolutionaryAlgorithm ) {
EvolutionaryAlgorithm ea = (EvolutionaryAlgorithm)trainer;
method = ea.getPopulation();
}
if( method==null ) {
method = trainer.getMethod();
}
EncogDirectoryPersistence.saveObject(resourceFile, method);
EncogLogging.log(EncogLogging.LEVEL_DEBUG, "save to:" + resourceID);
trainingSet.close();