Changeset 14836 for branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
- Timestamp:
- 04/10/17 15:48:20 (7 years ago)
- Location:
- branches/TSNE/HeuristicLab.Algorithms.DataAnalysis
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 60 61 61 62 #region linear regression 62 protected override void Run( ) {63 protected override void Run(CancellationToken cancellationToken) { 63 64 double rmsError, cvRmsError; 64 65 var solution = CreateLinearRegressionSolution(Problem.ProblemData, out rmsError, out cvRmsError); … … 73 74 IEnumerable<string> allowedInputVariables = problemData.AllowedInputVariables; 74 75 IEnumerable<int> rows = problemData.TrainingIndices; 75 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows); 76 var doubleVariables = allowedInputVariables.Where(dataset.VariableHasType<double>); 77 var factorVariableNames = allowedInputVariables.Where(dataset.VariableHasType<string>); 78 var factorVariables = AlglibUtil.GetFactorVariableValues(dataset, factorVariableNames, rows); 79 double[,] binaryMatrix = AlglibUtil.PrepareInputMatrix(dataset, factorVariables, rows); 80 double[,] doubleVarMatrix = AlglibUtil.PrepareInputMatrix(dataset, doubleVariables.Concat(new string[] { targetVariable }), rows); 81 var inputMatrix = binaryMatrix.HorzCat(doubleVarMatrix); 82 76 83 if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x))) 77 84 throw new NotSupportedException("Linear regression does not support NaN or infinity values in the input dataset."); … … 98 105 99 106 int col = 0; 100 foreach (string column in allowedInputVariables) { 107 foreach (var kvp in factorVariables) { 108 var varName = kvp.Key; 109 foreach (var cat in kvp.Value) { 110 BinaryFactorVariableTreeNode vNode = 111 (BinaryFactorVariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.BinaryFactorVariable().CreateTreeNode(); 112 vNode.VariableName = varName; 113 vNode.VariableValue = cat; 114 vNode.Weight = coefficients[col]; 115 addition.AddSubtree(vNode); 116 col++; 117 } 118 } 119 foreach (string column in doubleVariables) { 101 120 VariableTreeNode vNode = (VariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable().CreateTreeNode(); 102 121 vNode.VariableName = column; … … 110 129 addition.AddSubtree(cNode); 111 130 112 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTree Interpreter()), (IRegressionProblemData)problemData.Clone());131 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeLinearInterpreter()), (IRegressionProblemData)problemData.Clone()); 113 132 solution.Model.Name = "Linear Regression Model"; 114 133 solution.Name = "Linear Regression Solution";
Note: See TracChangeset
for help on using the changeset viewer.