Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/27/19 15:46:20 (6 years ago)
Author:
mkommend
Message:

#2952: Intermediate commit of refactoring RF models that is not yet finished.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2952_RF-ModelStorage/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs

    r16565 r17045  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
    2224using System.Threading;
     25using HEAL.Attic;
    2326using HeuristicLab.Common;
    2427using HeuristicLab.Core;
     
    2629using HeuristicLab.Optimization;
    2730using HeuristicLab.Parameters;
    28 using HEAL.Attic;
    2931using HeuristicLab.Problems.DataAnalysis;
    3032
     
    144146
    145147      if (CreateSolution) {
    146         var solution = new RandomForestRegressionSolution(model, (IRegressionProblemData)Problem.ProblemData.Clone());
     148        var solution = model.CreateRegressionSolution(Problem.ProblemData);
    147149        Results.Add(new Result(RandomForestRegressionModelResultName, "The random forest regression solution.", solution));
    148150      }
    149151    }
     152
    150153
    151154    // keep for compatibility with old API
     
    157160    }
    158161
    159     public static RandomForestModel CreateRandomForestRegressionModel(IRegressionProblemData problemData, int nTrees,
    160       double r, double m, int seed,
    161       out double rmsError, out double avgRelError, out double outOfBagRmsError, out double outOfBagAvgRelError) {
    162       return RandomForestModel.CreateRegressionModel(problemData, nTrees, r, m, seed,
    163         rmsError: out rmsError, avgRelError: out avgRelError, outOfBagRmsError: out outOfBagRmsError, outOfBagAvgRelError: out outOfBagAvgRelError);
     162    public static RandomForestModelFull CreateRandomForestRegressionModel(IRegressionProblemData problemData, int nTrees,
     163     double r, double m, int seed,
     164     out double rmsError, out double avgRelError, out double outOfBagRmsError, out double outOfBagAvgRelError) {
     165      return CreateRandomForestRegressionModel(problemData, problemData.TrainingIndices, nTrees, r, m, seed, out rmsError, out avgRelError, out outOfBagRmsError, out outOfBagAvgRelError);
     166    }
     167
     168    public static RandomForestModelFull CreateRandomForestRegressionModel(IRegressionProblemData problemData, IEnumerable<int> trainingIndices, int nTrees, double r, double m, int seed,
     169    out double rmsError, out double avgRelError, out double outOfBagRmsError, out double outOfBagAvgRelError) {
     170
     171      var variables = problemData.AllowedInputVariables.Concat(new string[] { problemData.TargetVariable });
     172      double[,] inputMatrix = problemData.Dataset.ToArray(variables, trainingIndices);
     173
     174      alglib.dfreport rep;
     175      var dForest = RandomForestUtil.CreateRandomForestModel(seed, inputMatrix, nTrees, r, m, 1, out rep);
     176
     177      rmsError = rep.rmserror;
     178      outOfBagRmsError = rep.oobrmserror;
     179      avgRelError = rep.avgrelerror;
     180      outOfBagAvgRelError = rep.oobavgrelerror;
     181
     182      return new RandomForestModelFull(dForest, problemData.TargetVariable, problemData.AllowedInputVariables);
     183
     184      //return RandomForestModel.CreateRegressionModel(problemData, nTrees, r, m, seed,
     185      //rmsError: out rmsError, avgRelError: out avgRelError, outOfBagRmsError: out outOfBagRmsError, outOfBagAvgRelError: out outOfBagAvgRelError);
    164186    }
    165187
Note: See TracChangeset for help on using the changeset viewer.