- Timestamp:
- 12/23/18 08:06:56 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r16389 r16448 41 41 [StorableClass] 42 42 public sealed class LinearRegression : FixedDataAnalysisAlgorithm<IRegressionProblem> { 43 private const string LinearRegressionModelResultName = "Linear regression solution"; 43 private const string SolutionResultName = "Linear regression solution"; 44 private const string ConfidenceSolutionResultName = "Solution with prediction intervals"; 44 45 45 46 [StorableConstructor] … … 62 63 protected override void Run(CancellationToken cancellationToken) { 63 64 double rmsError, cvRmsError; 65 // produce both solutions, to allow symbolic manipulation of LR solutions as well 66 // as the calculation of prediction intervals. 67 // There is no clean way to implement the new model class for LR as a symbolic model. 64 68 var solution = CreateSolution(Problem.ProblemData, out rmsError, out cvRmsError); 65 Results.Add(new Result(LinearRegressionModelResultName, "The linear regression solution.", solution)); 69 #pragma warning disable 168, 3021 70 var symbolicSolution = CreateLinearRegressionSolution(Problem.ProblemData, out rmsError, out cvRmsError); 71 #pragma warning restore 168, 3021 72 Results.Add(new Result(SolutionResultName, "The linear regression solution.", symbolicSolution)); 73 Results.Add(new Result(ConfidenceSolutionResultName, "Linear regression solution with parameter covariance matrix " + 74 "and calculation of prediction intervals", solution)); 66 75 Results.Add(new Result("Root mean square error", "The root of the mean of squared errors of the linear regression solution on the training set.", new DoubleValue(rmsError))); 67 76 Results.Add(new Result("Estimated root mean square error (cross-validation)", "The estimated root of the mean of squared errors of the linear regression solution via cross validation.", new DoubleValue(cvRmsError))); … … 88 97 double[] coefficients = new double[nFeatures + 1]; // last coefficient is for the constant 89 98 alglib.lrunpack(lm, out coefficients, out nFeatures); 90 91 int nFactorCoeff = factorVariables.Sum(kvp =>kvp.Value.Count());99 100 int nFactorCoeff = factorVariables.Sum(kvp => kvp.Value.Count()); 92 101 int nVarCoeff = doubleVariables.Count(); 93 102 var tree = LinearModelToTreeConverter.CreateTree(factorVariables, coefficients.Take(nFactorCoeff).ToArray(), … … 132 141 } 133 142 134 private static void PrepareData(IRegressionProblemData problemData, 135 out double[,] inputMatrix, 136 out IEnumerable<string> doubleVariables, 143 private static void PrepareData(IRegressionProblemData problemData, 144 out double[,] inputMatrix, 145 out IEnumerable<string> doubleVariables, 137 146 out IEnumerable<KeyValuePair<string, IEnumerable<string>>> factorVariables) { 138 147 var dataset = problemData.Dataset;
Note: See TracChangeset
for help on using the changeset viewer.