- Timestamp:
- 07/16/09 11:34:22 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMHelper.cs
r2148 r2165 9 9 namespace HeuristicLab.SupportVectorMachines { 10 10 public class SVMHelper { 11 public static SVM.Problem CreateSVMProblem(Dataset dataset, ItemList<IntData> allowedFeatures,int targetVariable, int start, int end) {11 public static SVM.Problem CreateSVMProblem(Dataset dataset, int targetVariable, int start, int end) { 12 12 int rowCount = end - start; 13 double[] samples = dataset.Samples; 13 List<int> skippedFeatures = new List<int>(); 14 for (int i = 0; i < dataset.Columns; i++) { 15 if (i != targetVariable) { 16 if (dataset.GetRange(i, start, end) == 0) 17 skippedFeatures.Add(i); 18 } 19 } 14 20 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 } 21 int maxColumns = dataset.Columns - skippedFeatures.Count(); 20 22 21 23 double[] targetVector = new double[rowCount]; 22 24 for (int i = 0; i < rowCount; i++) { 23 double value = samples[(start + i) * dataset.Columns + targetVariable];25 double value = dataset.GetValue(start + i, targetVariable); 24 26 targetVector[i] = value; 25 27 } … … 31 33 for (int row = 0; row < rowCount; row++) { 32 34 tempRow = new List<SVM.Node>(); 33 for (int col = 0; col < allowedFeatures.Count; col++) {34 if (!skippedFeatures.Contains(col) ) {35 double value = samples[(start + row) * dataset.Columns + allowedFeatures[col].Data];35 for (int col = 0; col < dataset.Columns; col++) { 36 if (!skippedFeatures.Contains(col) && col!=targetVariable) { 37 double value = dataset.GetValue(start + row, col); 36 38 if (!double.IsNaN(value)) 37 tempRow.Add(new SVM.Node( allowedFeatures[col].Data, value));39 tempRow.Add(new SVM.Node(col, value)); 38 40 } 39 41 } 40 if (!double.IsNaN( samples[(start + row) * dataset.Columns + targetVariable])) {42 if (!double.IsNaN(dataset.GetValue(start + row, targetVariable))) { 41 43 nodes[addedRows] = tempRow.ToArray(); 42 44 addedRows++; … … 44 46 } 45 47 46 return new SVM.Problem(targetVector.Length, targetVector, nodes, allowedFeatures.Max(x => x.Data));48 return new SVM.Problem(targetVector.Length, targetVector, nodes, maxColumns); 47 49 } 48 50 }
Note: See TracChangeset
for help on using the changeset viewer.