- Timestamp:
- 11/07/12 16:28:33 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/CSV/RegressionCSVInstanceProvider.cs
r8685 r8877 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.Globalization;26 25 using System.IO; 27 26 using System.Linq; 28 using System.Text;29 27 using HeuristicLab.Common; 30 28 using HeuristicLab.Problems.DataAnalysis; … … 67 65 var allowedInputVars = new List<string>(); 68 66 var trainingIndizes = Enumerable.Range(0, (csvFileParser.Rows * 2) / 3); 69 foreach (var variableName in dataset.DoubleVariables) { 70 if (trainingIndizes.Count() >= 2 && dataset.GetDoubleValues(variableName, trainingIndizes).Range() > 0 && 71 variableName != targetVar) 72 allowedInputVars.Add(variableName); 67 if (trainingIndizes.Count() >= 2) { 68 foreach (var variableName in dataset.DoubleVariables) { 69 if (dataset.GetDoubleValues(variableName, trainingIndizes).Range() > 0 && 70 variableName != targetVar) 71 allowedInputVars.Add(variableName); 72 } 73 } else { 74 allowedInputVars.AddRange(dataset.DoubleVariables.Where(x => !x.Equals(targetVar))); 73 75 } 74 76 … … 86 88 } 87 89 88 public override IRegressionProblemData ImportData(string path, DataAnalysisImportType type) { 89 TableFileParser csvFileParser = new TableFileParser(); 90 csvFileParser.Parse(path); 91 90 protected override IRegressionProblemData ImportData(string path, RegressionImportType type, TableFileParser csvFileParser) { 92 91 List<IList> values = csvFileParser.Values; 93 92 if (type.Shuffle) { … … 95 94 } 96 95 Dataset dataset = new Dataset(csvFileParser.VariableNames, values); 97 string targetVar = dataset.DoubleVariables.Last();98 96 99 97 // turn of input variables that are constant in the training partition … … 105 103 foreach (var variableName in dataset.DoubleVariables) { 106 104 if (dataset.GetDoubleValues(variableName, trainingIndizes).Range() > 0 && 107 variableName != t argetVar)105 variableName != type.TargetVariable) 108 106 allowedInputVars.Add(variableName); 109 107 } 110 108 } else { 111 allowedInputVars.AddRange(dataset.DoubleVariables.Where(x => x.Equals(targetVar)));109 allowedInputVars.AddRange(dataset.DoubleVariables.Where(x => !x.Equals(type.TargetVariable))); 112 110 } 113 111 114 RegressionProblemData regressionData = new RegressionProblemData(dataset, allowedInputVars, t argetVar);112 RegressionProblemData regressionData = new RegressionProblemData(dataset, allowedInputVars, type.TargetVariable); 115 113 116 114 regressionData.TrainingPartition.Start = 0; … … 123 121 return regressionData; 124 122 } 125 126 public override bool CanExportData {127 get { return true; }128 }129 public override void ExportData(IRegressionProblemData instance, string path) {130 var strBuilder = new StringBuilder();131 var colSep = CultureInfo.CurrentCulture.TextInfo.ListSeparator;132 foreach (var variable in instance.Dataset.VariableNames) {133 strBuilder.Append(variable.Replace(colSep, String.Empty) + colSep);134 }135 strBuilder.Remove(strBuilder.Length - colSep.Length, colSep.Length);136 strBuilder.AppendLine();137 138 var dataset = instance.Dataset;139 140 for (int i = 0; i < dataset.Rows; i++) {141 for (int j = 0; j < dataset.Columns; j++) {142 if (j > 0) strBuilder.Append(colSep);143 strBuilder.Append(dataset.GetValue(i, j));144 }145 strBuilder.AppendLine();146 }147 148 using (var writer = new StreamWriter(path)) {149 writer.Write(strBuilder);150 }151 }152 123 } 153 124 } -
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/RegressionInstanceProvider.cs
r8598 r8877 23 23 24 24 namespace HeuristicLab.Problems.Instances.DataAnalysis { 25 public abstract class RegressionInstanceProvider : DataAnalysisInstanceProvider<IRegressionProblemData > {25 public abstract class RegressionInstanceProvider : DataAnalysisInstanceProvider<IRegressionProblemData, RegressionImportType> { 26 26 } 27 27 }
Note: See TracChangeset
for help on using the changeset viewer.