Changeset 8206 for branches/GP-MoveOperators/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/ClassificationInstanceProvider.cs
- 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/Classification/ClassificationInstanceProvider.cs
r7965 r8206 20 20 #endregion 21 21 22 using System;23 using System.Collections;24 using System.Collections.Generic;25 using System.IO;26 using System.Linq;27 using System.Text;28 22 using HeuristicLab.Problems.DataAnalysis; 29 23 30 24 namespace HeuristicLab.Problems.Instances.DataAnalysis { 31 public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<IClassificationProblemData> { 32 public IClassificationProblemData LoadData(string path) { 33 TableFileParser csvFileParser = new TableFileParser(); 34 35 csvFileParser.Parse(path); 36 37 Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values); 38 string targetVar = csvFileParser.VariableNames.Where(x => dataset.DoubleVariables.Contains(x)).Last(); 39 IEnumerable<string> allowedInputVars = dataset.DoubleVariables.Where(x => !x.Equals(targetVar)); 40 41 ClassificationProblemData claData = new ClassificationProblemData(dataset, allowedInputVars, targetVar); 42 43 int trainingPartEnd = csvFileParser.Rows * 2 / 3; 44 claData.TrainingPartition.Start = 0; 45 claData.TrainingPartition.End = trainingPartEnd; 46 claData.TestPartition.Start = trainingPartEnd; 47 claData.TestPartition.End = csvFileParser.Rows; 48 int pos = path.LastIndexOf('\\'); 49 if (pos < 0) 50 claData.Name = path; 51 else { 52 pos++; 53 claData.Name = path.Substring(pos, path.Length - pos); 54 } 55 56 return claData; 57 } 58 59 public void SaveData(IClassificationProblemData instance, string path) { 60 StringBuilder strBuilder = new StringBuilder(); 61 62 foreach (var variable in instance.InputVariables) { 63 strBuilder.Append(variable + ";"); 64 } 65 strBuilder.Remove(strBuilder.Length - 1, 1); 66 strBuilder.AppendLine(); 67 68 Dataset dataset = instance.Dataset; 69 70 for (int i = 0; i < dataset.Rows; i++) { 71 for (int j = 0; j < dataset.Columns; j++) { 72 strBuilder.Append(dataset.GetValue(i, j) + ";"); 73 } 74 strBuilder.Remove(strBuilder.Length - 1, 1); 75 strBuilder.AppendLine(); 76 } 77 78 using (StreamWriter writer = new StreamWriter(path)) { 79 writer.Write(strBuilder); 80 } 81 } 82 83 public abstract IEnumerable<IDataDescriptor> GetDataDescriptors(); 84 public abstract IClassificationProblemData LoadData(IDataDescriptor descriptor); 85 86 public abstract string Name { get; } 87 public abstract string Description { get; } 88 public abstract Uri WebLink { get; } 89 public abstract string ReferencePublication { get; } 25 public abstract class ClassificationInstanceProvider : ProblemInstanceProvider<IClassificationProblemData> { 90 26 } 91 27 }
Note: See TracChangeset
for help on using the changeset viewer.