Practical overview
When it fits
Use it when a Ruby application needs to train or query an LIBSVM model directly from Ruby, rather than relying on LIBSVM’s separate command-line tools.
Who it is for
- Ruby developers adding SVM classification to an application.
- Practitioners prototyping a machine-learning workflow with labeled examples and feature vectors.
Documented uses
- Configure SVM parameters for a labeled dataset.
- Train a support-vector-machine model from Ruby code.
- Predict a label for new feature data.
Requirements & limits
- LIBSVM is bundled, so the README lists no additional dependencies.
- The gem contains native code; source builds on OS X require Xcode and its command-line tools.
- Bundler configuration must use
require: 'libsvm'because the load name differs from the gem name. - Preprocessing and parameter-search command-line tools are not included.
- The README names MIT terms for the gem and a separate LIBSVM license file; repository metadata lists BSD-3-Clause.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Train a model and make a prediction in Ruby
Use labeled feature vectors to train an SVM model and request a prediction for a new feature vector.
Before you start
- Ruby environment with the rb-libsvm gem installed.
- When building from source on OS X, Xcode and its command-line tools for the native-code compiler.
- Labeled examples represented as feature vectors.
Steps
Install the gem with
gem install rb-libsvm.Load it in Ruby with
require 'libsvm'; in a Bundler Gemfile, usegem 'rb-libsvm', require: 'libsvm'.Create
Libsvm::ProblemandLibsvm::SvmParameterobjects, configure parameters, convert feature arrays withLibsvm::Node.features, and pass labels and examples toproblem.set_examples.Train with
Libsvm::Model.train(problem, parameter)and callmodel.predictwith a feature vector.
Expected outcome
A trained LIBSVM model and a predicted label for the supplied feature vector.
Guide limitations
- The documented code is an example, not a guarantee of results for other datasets or environments.
- LIBSVM command-line tools for preprocessing and parameter finding are not included in this gem.
- On OS X, building from source requires Xcode and its command-line tools.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 21 November 2026
- Original website title
- febeling/rb-libsvm · Official homepage title · retained in its source language

