Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2148 for trunk


Ignore:
Timestamp:
07/07/09 13:06:31 (15 years ago)
Author:
mkommend
Message:

ignored dataset rows where the target variable is nan during !SVM learning (ticket #693)

Location:
trunk/sources/HeuristicLab.SupportVectorMachines/3.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMHelper.cs

    r1808 r2148  
    1212      int rowCount = end - start;
    1313      double[] samples = dataset.Samples;
    14      
    15       SVM.Node[][] nodes = new SVM.Node[rowCount][];
     14
     15      List<int> skippedFeatures = new List<int>();
     16      for (int i = 0; i < allowedFeatures.Count; i++) {
     17        if (dataset.GetRange(allowedFeatures[i].Data, start, end) == 0)
     18          skippedFeatures.Add(i);
     19      }
     20
     21      double[] targetVector = new double[rowCount];
     22      for (int i = 0; i < rowCount; i++) {
     23        double value = samples[(start + i) * dataset.Columns + targetVariable];
     24          targetVector[i] = value;
     25      }
     26      targetVector = targetVector.Where(x=> !double.IsNaN(x)).ToArray();
     27
     28      SVM.Node[][] nodes = new SVM.Node[targetVector.Length][];
    1629      List<SVM.Node> tempRow;
    17       double value;
     30      int addedRows = 0;
    1831      for (int row = 0; row < rowCount; row++) {
    1932        tempRow = new List<SVM.Node>();
    2033        for (int col = 0; col < allowedFeatures.Count; col++) {
    21           value = samples[(start + row) * dataset.Columns + allowedFeatures[col].Data];
    22           if(!double.IsNaN(value))
    23             tempRow.Add(new SVM.Node(allowedFeatures[col].Data, value));
     34          if (!skippedFeatures.Contains(col)) {
     35            double value = samples[(start + row) * dataset.Columns + allowedFeatures[col].Data];
     36            if (!double.IsNaN(value))
     37              tempRow.Add(new SVM.Node(allowedFeatures[col].Data, value));
     38          }
    2439        }
    25         nodes[row] = tempRow.ToArray();
     40        if (!double.IsNaN(samples[(start + row) * dataset.Columns + targetVariable])) {
     41          nodes[addedRows] = tempRow.ToArray();
     42          addedRows++;
     43        }
    2644      }
    2745
    28       double[] targetVector = new double[rowCount];
    29       for (int i = 0; i < rowCount; i++)
    30         targetVector[i] = samples[(start + i) * dataset.Columns + targetVariable];
    31 
    32       return new SVM.Problem(rowCount, targetVector, nodes, allowedFeatures.Max(x => x.Data));
     46      return new SVM.Problem(targetVector.Length, targetVector, nodes, allowedFeatures.Max(x => x.Data));
    3347    }
    3448  }
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorEvaluator.cs

    r2043 r2148  
    5656      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, modelData.RangeTransform);
    5757
    58       double[,] values = new double[end-start, 2];
    59       for (int i = 0; i < end - start; i++) {
     58      double[,] values = new double[scaledProblem.Count, 2];
     59      for (int i = 0; i < scaledProblem.Count; i++) {
    6060        values[i,0] = SVM.Prediction.Predict(modelData.Model, scaledProblem.X[i]);
    6161        values[i,1] = dataset.GetValue(start + i,targetVariable);
Note: See TracChangeset for help on using the changeset viewer.