Changeset 7805 for branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/RegressionInstanceProvider.cs
- Timestamp:
- 05/14/12 15:21:28 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/RegressionInstanceProvider.cs
r7759 r7805 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.Globalization; 25 26 using System.IO; 26 27 using System.Linq; … … 29 30 30 31 namespace HeuristicLab.Problems.Instances.Regression { 31 public abstract class RegressionInstanceProvider : IProblemInstanceProvider<RegressionProblemData> { 32 public RegressionProblemData LoadData(string path) { 33 TableFileParser csvFileParser = new TableFileParser(); 34 csvFileParser.Parse(path); 32 public abstract class RegressionInstanceProvider : IProblemInstanceProvider<IRegressionProblemData> { 35 33 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)); 34 public IRegressionProblemData LoadData(string path) { 35 NumberFormatInfo numberFormat; 36 DateTimeFormatInfo dateFormat; 37 char separator; 38 TableFileParser.DetermineFileFormat(path, out numberFormat, out dateFormat, out separator); 39 39 40 RegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar); 40 IRegressionProblemData regData = LoadData(new FileStream(path, FileMode.Open), numberFormat, dateFormat, separator); 41 41 42 int pos = path.LastIndexOf('\\'); 42 43 if (pos < 0) … … 46 47 regData.Name = path.Substring(pos, path.Length - pos); 47 48 } 49 return regData; 50 } 51 52 protected IRegressionProblemData LoadData(Stream stream, NumberFormatInfo numberFormat, DateTimeFormatInfo dateFormat, char separator) { 53 TableFileParser csvFileParser = new TableFileParser(); 54 55 csvFileParser.Parse(stream, numberFormat, dateFormat, separator); 56 57 Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values); 58 string targetVar = csvFileParser.VariableNames.Last(); 59 IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar)); 60 61 RegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar); 48 62 49 63 int trainingPartEnd = csvFileParser.Rows * 2 / 3; … … 52 66 regData.TestPartition.Start = trainingPartEnd; 53 67 regData.TestPartition.End = csvFileParser.Rows; 68 54 69 return regData; 55 70 } 56 71 57 public void SaveData( RegressionProblemData instance, string path) {72 public void SaveData(IRegressionProblemData instance, string path) { 58 73 StringBuilder strBuilder = new StringBuilder(); 59 74 … … 80 95 81 96 public abstract IEnumerable<IDataDescriptor> GetDataDescriptors(); 82 public abstract RegressionProblemData LoadData(IDataDescriptor descriptor);97 public abstract IRegressionProblemData LoadData(IDataDescriptor descriptor); 83 98 84 99 public abstract string Name { get; }
Note: See TracChangeset
for help on using the changeset viewer.