public void TimeSeriesCrossValidation_GetValidationTargets() { var random = new Random(23); var targets = Enumerable.Range(0, 100).Select(v => (double)random.Next()).ToArray(); var initialTrainingSize = 5; var sut = new TimeSeriesCrossValidation <double>(initialTrainingSize); var actual = sut.GetValidationTargets(targets); var expected = targets.Skip(initialTrainingSize).ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void TimeSeriesCrossValidation_Validate_MaxTrainingSetSize() { var(observations, targets) = DataSetUtilities.LoadDecisionTreeDataSet(); var sut = new TimeSeriesCrossValidation <double>(initialTrainingSize: 5, maxTrainingSetSize: 10); var timeSeriesPredictions = sut.Validate(new RegressionDecisionTreeLearner(), observations, targets); var timeSeriesTargets = sut.GetValidationTargets(targets); var metric = new MeanSquaredErrorRegressionMetric(); var error = metric.Error(timeSeriesTargets, timeSeriesPredictions); Assert.AreEqual(0.27296549371962692, error, 0.00001); }
public void TimeSeriesCrossValidation_Validate_MaxTrainingSetSize_And_RetrainInterval() { var(observations, targets) = DataSetUtilities.LoadDecisionTreeDataSet(); var sut = new TimeSeriesCrossValidation <double>(initialTrainingSize: 5, maxTrainingSetSize: 30, retrainInterval: 5); var timeSeriesPredictions = sut.Validate(new RegressionDecisionTreeLearner(), observations, targets); var timeSeriesTargets = sut.GetValidationTargets(targets); var metric = new MeanSquaredErrorRegressionMetric(); var error = metric.Error(timeSeriesTargets, timeSeriesPredictions); Assert.AreEqual(0.13010151998135897, error, 0.00001); }
public void TimeSeriesCrossValidation_Validate_RetrainInterval() { var(observations, targets) = DataSetUtilities.LoadDecisionTreeDataSet(); var sut = new TimeSeriesCrossValidation <double>(initialTrainingSize: 5, retrainInterval: 5); var learner = new RegressionDecisionTreeLearner(); var timeSeriesPredictions = sut.Validate(learner, observations, targets); var timeSeriesTargets = sut.GetValidationTargets(targets); var metric = new MeanSquaredErrorRegressionMetric(); var error = metric.Error(timeSeriesTargets, timeSeriesPredictions); Assert.AreEqual(0.096346937132994928, error, 0.00001); }
public void TimeSeriesCrossValidation_Validate_MaxTrainingSetSize_And_RetrainInterval() { var targetName = "T"; var parser = new CsvParser(() => new StringReader(Resources.DecisionTreeData)); var observations = parser.EnumerateRows(v => !v.Contains(targetName)).ToF64Matrix(); var targets = parser.EnumerateRows(targetName).ToF64Vector(); var sut = new TimeSeriesCrossValidation <double>(initialTrainingSize: 5, maxTrainingSetSize: 30, retrainInterval: 5); var timeSeriesPredictions = sut.Validate(new RegressionDecisionTreeLearner(), observations, targets); var timeSeriesTargets = sut.GetValidationTargets(targets); var metric = new MeanSquaredErrorRegressionMetric(); var error = metric.Error(timeSeriesTargets, timeSeriesPredictions); Assert.AreEqual(0.11347313000447182, error, 0.00001); }