Class: SvmToolkit::Svm
- Inherits:
-
Object
- Object
- SvmToolkit::Svm
- Defined in:
- lib/svm_toolkit/svm.rb
Overview
Extends the Java SVM class
Available methods include:
Svm.svm_train(problem, param)
- problem
-
instance of Problem
- param
-
instance of Parameter
Returns an instance of Model
Svm.svm_cross_validation(problem, param, nr_folds, target)
- problem
-
instance of Problem
- param
-
instance of Parameter
- nr_fold
-
number of folds
- target
-
resulting predictions in an array
Defined Under Namespace
Classes: ContourDisplay, CrossValidationSearch, SvmTrainer
Class Method Summary collapse
-
.cross_validation_search(training_set, cross_valn_set, costs = [-2,-1,0,1,2,3].collect {|i| 2**i}, gammas = [-2,-1,0,1,2,3].collect {|i| 2**i}, params = {}) ⇒ Object
Perform cross validation search on given gamma/cost values, using an RBF kernel, returning the best performing model and optionally displaying a contour map of performance.
Class Method Details
.cross_validation_search(training_set, cross_valn_set, costs = [-2,-1,0,1,2,3].collect {|i| 2**i}, gammas = [-2,-1,0,1,2,3].collect {|i| 2**i}, params = {}) ⇒ Object
Perform cross validation search on given gamma/cost values, using an RBF kernel, returning the best performing model and optionally displaying a contour map of performance.
- training_set
-
instance of Problem, used for training
- cross_valn_set
-
instance of Problem, used for evaluating models
- costs
-
array of cost values to search across
- gammas
-
array of gamma values to search across
- params
-
Optional parameters include:
-
:evaluator => Evaluator::OverallAccuracy, the name of the class to use for computing performance
-
:show_plot => false, whether to display contour plot
Returns an instance of Model, the best performing model.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/svm_toolkit/svm.rb', line 39 def Svm.cross_validation_search(training_set, cross_valn_set, costs = [-2,-1,0,1,2,3].collect {|i| 2**i}, gammas = [-2,-1,0,1,2,3].collect {|i| 2**i}, params = {}) evaluator = params.fetch :evaluator, Evaluator::OverallAccuracy show_plot = params.fetch :show_plot, false fjp = ForkJoinPool.new task = CrossValidationSearch.new gammas, costs, training_set, cross_valn_set, evaluator results, best_model = fjp.invoke task if show_plot ContourDisplay.new(costs.collect {|n| Math.log2(n)}, gammas.collect {|n| Math.log2(n)}, results) end return best_model end |