Changeset 7759 for branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ClassificationInstanceProvider.cs
- Timestamp:
- 04/24/12 16:37:40 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ClassificationInstanceProvider.cs
r7685 r7759 26 26 using System.Linq; 27 27 using System.Text; 28 using HeuristicLab.Problems.DataAnalysis; 28 29 29 30 namespace HeuristicLab.Problems.Instances.Classification { 30 public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<Classification Data> {31 public Classification Data LoadData(string path) {31 public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<ClassificationProblemData> { 32 public ClassificationProblemData LoadData(string path) { 32 33 TableFileParser csvFileParser = new TableFileParser(); 33 34 csvFileParser.Parse(path); 34 35 35 ClassificationData claData = new ClassificationData(); 36 Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values); 37 string targetVar = csvFileParser.VariableNames.Last(); 38 IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar)); 39 40 ClassificationProblemData claData = new ClassificationProblemData(dataset, allowedInputVars, targetVar); 36 41 int pos = path.LastIndexOf('\\'); 37 42 if (pos < 0) … … 41 46 claData.Name = path.Substring(pos, path.Length - pos); 42 47 } 43 claData.InputVariables = new List<string>(csvFileParser.VariableNames).ToArray();44 claData.TargetVariable = csvFileParser.VariableNames.Last();45 claData.AllowedInputVariables = claData.InputVariables.Where(x => !x.Equals(claData.TargetVariable)).ToArray();46 //convert to multidimensional array47 List<IList> values = csvFileParser.Values;48 claData.Values = new double[values.First().Count, values.Count];49 for (int i = 0; i < values.Count; i++) {50 for (int j = 0; j < values.First().Count; j++) {51 claData.Values[j, i] = (double)values[i][j];52 }53 }54 48 55 49 int trainingPartEnd = csvFileParser.Rows * 2 / 3; 56 claData.TrainingPartition Start = 0;57 claData.TrainingPartition End = trainingPartEnd;58 claData.TestPartition Start = trainingPartEnd;59 claData.TestPartition End = csvFileParser.Rows;50 claData.TrainingPartition.Start = 0; 51 claData.TrainingPartition.End = trainingPartEnd; 52 claData.TestPartition.Start = trainingPartEnd; 53 claData.TestPartition.End = csvFileParser.Rows; 60 54 return claData; 61 55 } 62 56 63 public void SaveData(Classification Data instance, string path) {57 public void SaveData(ClassificationProblemData instance, string path) { 64 58 StringBuilder strBuilder = new StringBuilder(); 65 59 … … 70 64 strBuilder.AppendLine(); 71 65 72 double[,] values = instance.Values;66 Dataset dataset = instance.Dataset; 73 67 74 for (int i = 0; i < values.GetLength(0); i++) {75 for (int j = 0; j < values.GetLength(1); j++) {76 strBuilder.Append( values[i, j]+ ";");68 for (int i = 0; i < dataset.Rows; i++) { 69 for (int j = 0; j < dataset.Columns; j++) { 70 strBuilder.Append(dataset.GetValue(i, j) + ";"); 77 71 } 78 72 strBuilder.Remove(strBuilder.Length - 1, 1); … … 86 80 87 81 public abstract IEnumerable<IDataDescriptor> GetDataDescriptors(); 88 public abstract Classification Data LoadData(IDataDescriptor descriptor);82 public abstract ClassificationProblemData LoadData(IDataDescriptor descriptor); 89 83 90 84 public abstract string Name { get; } … … 92 86 public abstract Uri WebLink { get; } 93 87 public abstract string ReferencePublication { get; } 94 95 public IProblemInstanceConsumer<ClassificationData> Consumer { get; set; }96 88 } 97 89 }
Note: See TracChangeset
for help on using the changeset viewer.