Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/03/12 13:41:36 (12 years ago)
Author:
sforsten
Message:

#1782:

  • renamed CanSave to CanExportData and SaveData to ExportData
  • added the same functionality for importing problem instance as we implemented for exporting
  • some special changes had to be made in Problems.Instances.VehicleRouting
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/CSV/ClassifiactionCSVInstanceProvider.cs

    r8180 r8192  
    2020#endregion
    2121
    22 
    2322using System;
    2423using System.Collections.Generic;
    2524using System.IO;
     25using System.Linq;
    2626using System.Text;
    2727using HeuristicLab.Problems.DataAnalysis;
     28
    2829namespace HeuristicLab.Problems.Instances.DataAnalysis {
    2930  public class ClassificationCSVInstanceProvider : ClassificationInstanceProvider {
     
    4344    }
    4445
    45     public override bool CanSaveData {
    46       get { return true; }
    47     }
    48 
    4946    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    5047      return new List<IDataDescriptor>();
    5148    }
    5249
    53     public override void SaveData(IClassificationProblemData instance, string path) {
     50    public override IClassificationProblemData LoadData(IDataDescriptor descriptor) {
     51      throw new NotImplementedException();
     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) {
    5488      StringBuilder strBuilder = new StringBuilder();
    5589
     
    74108      }
    75109    }
    76 
    77     public override IClassificationProblemData LoadData(IDataDescriptor descriptor) {
    78       throw new NotImplementedException();
    79     }
    80110  }
    81111}
Note: See TracChangeset for help on using the changeset viewer.