Changeset 16141 for branches/2817-BinPackingSpeedup/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineUtil.cs
- Timestamp:
- 09/14/18 11:47:37 (6 years ago)
- Location:
- branches/2817-BinPackingSpeedup
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineUtil.cs
r16140 r16141 35 35 public class SupportVectorMachineUtil { 36 36 /// <summary> 37 /// Transforms <paramref name="problemData"/> into a data structure as needed by libSVM. 38 /// </summary> 39 /// <param name="problemData">The problem data to transform</param> 37 /// Transforms <paramref name="dataset"/> into a data structure as needed by libSVM. 38 /// </summary> 39 /// <param name="dataset">The source dataset</param> 40 /// <param name="targetVariable">The target variable</param> 41 /// <param name="inputVariables">The selected input variables to include in the svm_problem.</param> 40 42 /// <param name="rowIndices">The rows of the dataset that should be contained in the resulting SVM-problem</param> 41 43 /// <returns>A problem data type that can be used to train a support vector machine.</returns> 42 44 public static svm_problem CreateSvmProblem(IDataset dataset, string targetVariable, IEnumerable<string> inputVariables, IEnumerable<int> rowIndices) { 43 double[] targetVector = dataset.GetDoubleValues(targetVariable, rowIndices).ToArray(); 44 svm_node[][] nodes = new svm_node[targetVector.Length][]; 45 double[] targetVector ; 46 var nRows = rowIndices.Count(); 47 if (string.IsNullOrEmpty(targetVariable)) { 48 // if the target variable is not set (e.g. for prediction of a trained model) we just use a zero vector 49 targetVector = new double[nRows]; 50 } else { 51 targetVector = dataset.GetDoubleValues(targetVariable, rowIndices).ToArray(); 52 } 53 svm_node[][] nodes = new svm_node[nRows][]; 45 54 int maxNodeIndex = 0; 46 55 int svmProblemRowIndex = 0; … … 66 75 67 76 /// <summary> 77 /// Transforms <paramref name="dataset"/> into a data structure as needed by libSVM for prediction. 78 /// </summary> 79 /// <param name="dataset">The problem data to transform</param> 80 /// <param name="inputVariables">The selected input variables to include in the svm_problem.</param> 81 /// <param name="rowIndices">The rows of the dataset that should be contained in the resulting SVM-problem</param> 82 /// <returns>A problem data type that can be used for prediction with a trained support vector machine.</returns> 83 public static svm_problem CreateSvmProblem(IDataset dataset, IEnumerable<string> inputVariables, IEnumerable<int> rowIndices) { 84 // for prediction we don't need a target variable 85 return CreateSvmProblem(dataset, string.Empty, inputVariables, rowIndices); 86 } 87 88 /// <summary> 68 89 /// Instantiate and return a svm_parameter object with default values. 69 90 /// </summary>
Note: See TracChangeset
for help on using the changeset viewer.