example-2.rb 868 B

123456789101112131415161718192021222324252627
  1. # Example to illustrate reading a dataset from file
  2. #
  3. require "svm-toolkit"
  4. include SvmToolkit
  5. Dataset = Problem.from_file("australian_scale.txt")
  6. puts "Number of instances #{Dataset.size}"
  7. model = Svm.svm_train(Dataset, Parameter.new(
  8. :svm_type => Parameter::C_SVC,
  9. :kernel_type => Parameter::RBF,
  10. :cost => 1,
  11. :gamma => 4
  12. ))
  13. performance = model.evaluate_dataset(Dataset, :evaluator => Evaluator::OverallAccuracy)
  14. puts performance
  15. performance = model.evaluate_dataset(Dataset, :evaluator => Evaluator::ClassPrecision(-1))
  16. puts performance
  17. performance = model.evaluate_dataset(Dataset, :evaluator => Evaluator::ClassRecall(-1))
  18. puts performance
  19. performance = model.evaluate_dataset(Dataset, :evaluator => Evaluator::ClassPrecision(1))
  20. puts performance
  21. performance = model.evaluate_dataset(Dataset, :evaluator => Evaluator::ClassRecall(1))
  22. puts performance