Changeset 13721 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs
- Timestamp:
- 03/23/16 16:19:04 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs
r13707 r13721 317 317 // just produce an ensemble solution for now (TODO: correct scaling or linear regression for ensemble model weights) 318 318 319 var ensembleModel = new RegressionEnsembleModel(models) { AverageModelEstimates = false }; 320 var ensembleSolution = ensembleModel.CreateRegressionSolution((IRegressionProblemData)problemData.Clone()); 319 var ensembleSolution = CreateEnsembleSolution(models, (IRegressionProblemData)problemData.Clone()); 321 320 Results.Add(new Result("EnsembleSolution", ensembleSolution)); 322 321 } … … 326 325 alg.Prepare(true); 327 326 } 327 } 328 329 private static IRegressionEnsembleSolution CreateEnsembleSolution(List<IRegressionModel> models, 330 IRegressionProblemData problemData) { 331 var rows = problemData.TrainingPartition.Size; 332 var features = models.Count; 333 double[,] inputMatrix = new double[rows, features + 1]; 334 335 //add model estimates 336 for (int m = 0; m < models.Count; m++) { 337 var model = models[m]; 338 var estimates = model.GetEstimatedValues(problemData.Dataset, problemData.TrainingIndices); 339 int estimatesCounter = 0; 340 foreach (var estimate in estimates) { 341 inputMatrix[estimatesCounter, m] = estimate; 342 estimatesCounter++; 343 } 344 } 345 346 //add target 347 var targets = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices); 348 int targetCounter = 0; 349 foreach (var target in targets) { 350 inputMatrix[targetCounter, models.Count] = target; 351 targetCounter++; 352 } 353 354 alglib.linearmodel lm = new alglib.linearmodel(); 355 alglib.lrreport ar = new alglib.lrreport(); 356 double[] coefficients; 357 int retVal = 1; 358 alglib.lrbuildz(inputMatrix, rows, features, out retVal, out lm, out ar); 359 if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression solution"); 360 361 alglib.lrunpack(lm, out coefficients, out features); 362 363 var ensembleModel = new RegressionEnsembleModel(models, coefficients.Take(models.Count)) { AverageModelEstimates = false }; 364 var ensembleSolution = ensembleModel.CreateRegressionSolution((IRegressionProblemData)problemData.Clone()); 365 return ensembleSolution; 328 366 } 329 367
Note: See TracChangeset
for help on using the changeset viewer.