示例#1
0
        protected override void Run(CancellationToken cancellationToken)
        {
            double rmsError, avgRelError, outOfBagRmsError, outOfBagAvgRelError;

            if (SetSeedRandomly)
            {
                Seed = Random.RandomSeedGenerator.GetSeed();
            }
            var model = CreateRandomForestRegressionModel(Problem.ProblemData, NumberOfTrees, R, M, Seed,
                                                          out rmsError, out avgRelError, out outOfBagRmsError, out outOfBagAvgRelError);

            Results.Add(new Result("Root mean square error", "The root of the mean of squared errors of the random forest regression solution on the training set.", new DoubleValue(rmsError)));
            Results.Add(new Result("Average relative error", "The average of relative errors of the random forest regression solution on the training set.", new PercentValue(avgRelError)));
            Results.Add(new Result("Root mean square error (out-of-bag)", "The out-of-bag root of the mean of squared errors of the random forest regression solution.", new DoubleValue(outOfBagRmsError)));
            Results.Add(new Result("Average relative error (out-of-bag)", "The out-of-bag average of relative errors of the random forest regression solution.", new PercentValue(outOfBagAvgRelError)));

            IRegressionSolution solution = null;

            if (ModelCreation == ModelCreation.Model)
            {
                solution = model.CreateRegressionSolution(Problem.ProblemData);
            }
            else if (ModelCreation == ModelCreation.SurrogateModel)
            {
                var problemData    = Problem.ProblemData;
                var surrogateModel = new RandomForestModelSurrogate(model, problemData.TargetVariable, problemData, Seed, NumberOfTrees, R, M);
                solution = surrogateModel.CreateRegressionSolution(problemData);
            }

            if (solution != null)
            {
                Results.Add(new Result(RandomForestRegressionModelResultName, "The random forest regression solution.", solution));
            }
        }
        private RandomForestModelSurrogate(RandomForestModelSurrogate original, Cloner cloner) : base(original, cloner)
        {
            IRandomForestModel clonedModel = null;

            if (original.actualModel.IsValueCreated)
            {
                clonedModel = cloner.Clone(original.ActualModel);
            }
            actualModel = new Lazy <IRandomForestModel>(CreateLazyInitFunc(clonedModel)); // only capture clonedModel in the closure

            // clone data which is necessary to rebuild the model
            this.originalTrainingData = cloner.Clone(original.originalTrainingData);
            this.seed        = original.seed;
            this.classValues = original.classValues;
            this.nTrees      = original.nTrees;
            this.r           = original.r;
            this.m           = original.m;
        }