Changeset 8206 for branches/GP-MoveOperators/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/CSV
- Timestamp:
- 07/03/12 16:46:35 (12 years ago)
- Location:
- branches/GP-MoveOperators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-MoveOperators
- Property svn:mergeinfo changed
/trunk/sources merged: 8084,8088-8090,8092-8100,8102-8113,8115,8117-8132,8134-8146,8148-8156,8158-8160,8163-8170,8173-8176,8178-8190,8192-8205
- Property svn:mergeinfo changed
-
branches/GP-MoveOperators/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/CSV/RegressionCSVInstanceProvider.cs
r7860 r8206 20 20 #endregion 21 21 22 23 22 using System; 24 23 using System.Collections.Generic; 24 using System.IO; 25 using System.Linq; 26 using System.Text; 25 27 using HeuristicLab.Problems.DataAnalysis; 28 26 29 namespace HeuristicLab.Problems.Instances.DataAnalysis { 27 30 public class RegressionCSVInstanceProvider : RegressionInstanceProvider { 28 31 public override string Name { 29 get { return "C SV Problem Provider"; }32 get { return "Comma-separated Values File"; } 30 33 } 31 34 public override string Description { … … 44 47 return new List<IDataDescriptor>(); 45 48 } 46 47 49 public override IRegressionProblemData LoadData(IDataDescriptor descriptor) { 48 50 throw new NotImplementedException(); 49 51 } 52 53 public override bool CanImportData { 54 get { return true; } 55 } 56 public override IRegressionProblemData ImportData(string path) { 57 TableFileParser csvFileParser = new TableFileParser(); 58 csvFileParser.Parse(path); 59 60 Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values); 61 string targetVar = csvFileParser.VariableNames.Where(x => dataset.DoubleVariables.Contains(x)).Last(); 62 63 IEnumerable<string> allowedInputVars = dataset.DoubleVariables.Where(x => !x.Equals(targetVar)); 64 65 IRegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar); 66 67 int trainingPartEnd = csvFileParser.Rows * 2 / 3; 68 regData.TrainingPartition.Start = 0; 69 regData.TrainingPartition.End = trainingPartEnd; 70 regData.TestPartition.Start = trainingPartEnd; 71 regData.TestPartition.End = csvFileParser.Rows; 72 73 int pos = path.LastIndexOf('\\'); 74 if (pos < 0) 75 regData.Name = path; 76 else { 77 pos++; 78 regData.Name = path.Substring(pos, path.Length - pos); 79 } 80 return regData; 81 } 82 83 public override bool CanExportData { 84 get { return true; } 85 } 86 public override void ExportData(IRegressionProblemData instance, string path) { 87 StringBuilder strBuilder = new StringBuilder(); 88 89 foreach (var variable in instance.InputVariables) { 90 strBuilder.Append(variable + ";"); 91 } 92 strBuilder.Remove(strBuilder.Length - 1, 1); 93 strBuilder.AppendLine(); 94 95 Dataset dataset = instance.Dataset; 96 97 for (int i = 0; i < dataset.Rows; i++) { 98 for (int j = 0; j < dataset.Columns; j++) { 99 strBuilder.Append(dataset.GetValue(i, j) + ";"); 100 } 101 strBuilder.Remove(strBuilder.Length - 1, 1); 102 strBuilder.AppendLine(); 103 } 104 105 using (StreamWriter writer = new StreamWriter(path)) { 106 writer.Write(strBuilder); 107 } 108 } 50 109 } 51 110 }
Note: See TracChangeset
for help on using the changeset viewer.