private RegressionEnsembleModel(RegressionEnsembleModel original, Cloner cloner)
     : base(original, cloner)
 {
     this.models                = original.Models.Select(cloner.Clone).ToList();
     this.modelWeights          = new List <double>(original.ModelWeights);
     this.averageModelEstimates = original.averageModelEstimates;
 }
    private static IRegressionEnsembleSolution CreateEnsembleSolution(List<IRegressionModel> models,
      IRegressionProblemData problemData) {
      var rows = problemData.TrainingPartition.Size;
      var features = models.Count;
      double[,] inputMatrix = new double[rows, features + 1];

      //add model estimates
      for (int m = 0; m < models.Count; m++) {
        var model = models[m];
        var estimates = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices);
        int estimatesCounter = 0;
        foreach (var estimate in estimates) {
          inputMatrix[estimatesCounter, m] = estimate;
          estimatesCounter++;
        }
      }

      //add target
      var targets = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices);
      int targetCounter = 0;
      foreach (var target in targets) {
        inputMatrix[targetCounter, models.Count] = target;
        targetCounter++;
      }

      alglib.linearmodel lm = new alglib.linearmodel();
      alglib.lrreport ar = new alglib.lrreport();
      double[] coefficients;
      int retVal = 1;
      alglib.lrbuildz(inputMatrix, rows, features, out retVal, out lm, out ar);
      if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression solution");

      alglib.lrunpack(lm, out coefficients, out features);

      var ensembleModel = new RegressionEnsembleModel(models, coefficients.Take(models.Count)) { AverageModelEstimates = false };
      var ensembleSolution = (IRegressionEnsembleSolution)ensembleModel.CreateRegressionSolution(problemData);      return ensembleSolution;
    }
 protected RegressionEnsembleModel(RegressionEnsembleModel original, Cloner cloner)
   : base(original, cloner) {
   this.models = original.Models.Select(m => cloner.Clone(m)).ToList();
 }
예제 #4
0
 private RegressionEnsembleModel(RegressionEnsembleModel original, Cloner cloner)
   : base(original, cloner) {
   this.models = original.Models.Select(cloner.Clone).ToList();
   this.modelWeights = new List<double>(original.ModelWeights);
   this.averageModelEstimates = original.averageModelEstimates;
 }
예제 #5
0
 protected RegressionEnsembleModel(RegressionEnsembleModel original, Cloner cloner)
     : base(original, cloner)
 {
     this.models = original.Models.Select(m => cloner.Clone(m)).ToList();
 }