Changeset 8206 for branches/GP-MoveOperators/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/CSV
- Timestamp:
- 07/03/12 16:46:35 (13 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/Classification/CSV/ClassifiactionCSVInstanceProvider.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 ClassificationCSVInstanceProvider : ClassificationInstanceProvider { 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 { … … 48 51 throw new NotImplementedException(); 49 52 } 53 54 public override bool CanImportData { 55 get { return true; } 56 } 57 public override IClassificationProblemData ImportData(string path) { 58 TableFileParser csvFileParser = new TableFileParser(); 59 60 csvFileParser.Parse(path); 61 62 Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values); 63 string targetVar = csvFileParser.VariableNames.Where(x => dataset.DoubleVariables.Contains(x)).Last(); 64 IEnumerable<string> allowedInputVars = dataset.DoubleVariables.Where(x => !x.Equals(targetVar)); 65 66 ClassificationProblemData claData = new ClassificationProblemData(dataset, allowedInputVars, targetVar); 67 68 int trainingPartEnd = csvFileParser.Rows * 2 / 3; 69 claData.TrainingPartition.Start = 0; 70 claData.TrainingPartition.End = trainingPartEnd; 71 claData.TestPartition.Start = trainingPartEnd; 72 claData.TestPartition.End = csvFileParser.Rows; 73 int pos = path.LastIndexOf('\\'); 74 if (pos < 0) 75 claData.Name = path; 76 else { 77 pos++; 78 claData.Name = path.Substring(pos, path.Length - pos); 79 } 80 81 return claData; 82 } 83 84 public override bool CanExportData { 85 get { return true; } 86 } 87 public override void ExportData(IClassificationProblemData instance, string path) { 88 StringBuilder strBuilder = new StringBuilder(); 89 90 foreach (var variable in instance.InputVariables) { 91 strBuilder.Append(variable + ";"); 92 } 93 strBuilder.Remove(strBuilder.Length - 1, 1); 94 strBuilder.AppendLine(); 95 96 Dataset dataset = instance.Dataset; 97 98 for (int i = 0; i < dataset.Rows; i++) { 99 for (int j = 0; j < dataset.Columns; j++) { 100 strBuilder.Append(dataset.GetValue(i, j) + ";"); 101 } 102 strBuilder.Remove(strBuilder.Length - 1, 1); 103 strBuilder.AppendLine(); 104 } 105 106 using (StreamWriter writer = new StreamWriter(path)) { 107 writer.Write(strBuilder); 108 } 109 } 50 110 } 51 111 }
Note: See TracChangeset
for help on using the changeset viewer.