esvm

Build StatusGitHubHex.pm

esvm is a simple, easy-to-use, and efficient Erlang library for Support Vector Machine (SVM) classification and regression, based on libsvm. It supports:

Overview

The Support Vector Machine (SVM) is a widely recognized technique for classifying large feature spaces reliably. It is a statistical model that leverages machine learning to capture complex relationships between variables.

The core idea of SVM is to find an optimal hyperplane that distinguishes between different classes. This hyperplane is selected to maximize the margin, ensuring superior generalization. SVMs perform exceptionally well in high-dimensional spaces and use memory efficiently by relying on a subset of training data points for decision-making.

However, SVMs may become inefficient when the number of features exceeds the number of samples.

Quick Start

Compile the project

rebar3 compile

Create a model

% Features should be a list of tuples where the first element is the class
% and the second is the feature vector.

Features = [
    {1, [1, 3, 4, 5]},
    {0, [0, 2, 4, 6]},
    {1, [0, 2, 4, 6]}
],

FeaturesCount = length(Features),

{ok, Model} = esvm:model_create(Features, FeaturesCount, [
    {<<"svm_type">>, ?SVM_TYPE_C_SVC},
    {<<"kernel_type">>, ?KERNEL_TYPE_RBF}
]).

Model parameters

When creating a model, the following parameters can be tuned:

Save a model

true = esvm:model_save(Model, <<"path/file.model">>).

Load an existing model

{ok, Model} = esvm:model_load(<<"path/file.model">>).

Make a prediction

{ok, PredictedClass} = esvm:model_predict(Model, Feature).

Tests

Inside the classification_test.erl file in the test folder, you will find an example of creating a model to classify SMS messages as spam or not using SVM.

The dataset used to train the model can be downloaded from here.

To run the tests, execute the following command from the project root:

rebar3 eunit