/// <summary> /// Specify a validation set to hold back. /// </summary> /// <param name="validationPercent">The percent to use for validation.</param> /// <param name="shuffle">True to shuffle.</param> /// <param name="seed">The seed for random generation.</param> public void HoldBackValidation(double validationPercent, bool shuffle, int seed) { IList <DataDivision> dataDivisionList = new List <DataDivision>(); dataDivisionList.Add(new DataDivision(1.0 - validationPercent)); // Training dataDivisionList.Add(new DataDivision(validationPercent)); // Validation _dataset.Divide(dataDivisionList, shuffle, new MersenneTwisterGenerateRandom((uint)seed)); TrainingDataset = dataDivisionList[0].Dataset; ValidationDataset = dataDivisionList[1].Dataset; }
public void Run() { var bestMethod = _model.Crossvalidate(5, true) as IMLRegression; Console.WriteLine($"Training error: {_model.CalculateError(bestMethod, _model.TrainingDataset)}"); Console.WriteLine($"Validation error: {_model.CalculateError(bestMethod, _model.ValidationDataset)}"); var dataDivisions = new List <DataDivision> { new DataDivision(0.5), new DataDivision(0.5) }; _dataset.Divide(dataDivisions, true, new MersenneTwisterGenerateRandom()); foreach (var data in dataDivisions[0].Dataset) { var result = bestMethod.Compute(data.Input); Console.WriteLine($"Result: {result}, Actual: {data.Ideal}"); } EncogDirectoryPersistence.SaveObject(new FileInfo("SvmModel.eg"), bestMethod); }