The svMathematica package implements some support vectorbased algorithms for machine learning. The package is described in a paper presented at the 2009 Mathematica Italian User Group Meeting.
The package requires a working installation of Wolfram Mathematica. Moreover, several of the learning algorithms can be executed exploiting different implementations, and some of the latter rely on external computing components, which shall be previously installed. The following table lists these components and the implementation requiring them.
External component  svMathematica functionality 

ampl and snopt 
svmClassificationAMPL , svmRegressionAMPL

Svmlight  svmClassificationSVMLight 
python 
svmClassificationPython , svmRegressionPython

In turn, the pythonbased components depend on the python packages CvxOpt and NumPy.
Note the external components can be installed in other directories. Their actual location will affect the symlink creation on step 3 of the Install instructions below.
The software is available on GitHub, and is installed as follows.
svMathematica
directory in a place chosen according to the following table, depending on the operating system you use and your preference for a userbased or a systemwide installation.
OS  Userbased installation  Systemwide installation 

Mac OS X  ~/Library/Mathematica/Applications 
/Library/Mathematica/Applications 
Linux  ~/.Mathematica/Applications 
R/AddOns/Applications 
Windows  ~/Applications Data/Mathematica/Applications 
R/AddOns/Applications 
~
denotes the user's home directory in Mac OS X and Linux and the user's directory inside Documents and Settings
in Windows, while R
denotes the Mathematica root directory.$Path
variable will also work.
init.m
in the directory created on step 2.classificationDefs.py
in the same directory of previous steps. Moreover, the file test.py
can be executed in order to verify that the NumPy and CvxOpt packages are correctly installed.svMathematicausage.nb
.The package is loaded as usual.
In[1]:= <<svMathematica`
The starting point of a learning algorithm is a labelled sample, which svMathematica encodes in two lists, referred to as patterns
and labes
henceforth, containing patterns (lists of numeric values) and labels (lists of 1
or 1
for classification problems and lists of numerical values for regression problems).
Besides the functions actually running learning algorithms, a set of graphics routines is provided: svmClassificationSamplePlot
and svmRegressionSamplePlot
plot classification and regression samples, respectively.
In[2]:= grClassPoints = svmClassificationSamplePlot[pattern, label,Frame > True]
In[3]:= grRegrPoints = svmRegressionSamplePlot[pattern, label, Frame >True]
These functions accept two arguments, specifying respectively patterns and labels, as well as standard options for graphical routines.
The package provides two families of learning algorithms, solving classification and regression problems. The first family is executed by svmClassification
, accepting patterns and labels as arguments and outputting a classification function:
In[4]:= classifier = svmClassification[pattern, label]
The returned value is a function which can be queried for classification of new patterns or for plotting purposes, using the svmDecisionFunctionPlot
:
In[5]:= grClassifier = svmDecisionFunctionPlot[classifier, {x, 0, 1}, {y, 0, 1}, margin > False]; In[6]:= Show[grClassPoints,grClassifier]
The function svmClassification
, besides patterns and labels, accepts several options allowing to specify specific kernels or tradeoff constant values, as well as a specific implementation of the algorithm and other parameters:
In[7]:= Options[svmClassification] Out[7]= {c > \[Infinity], kernel > "linear", bVarThreshold > 0.0001, implementation > svmClassificationPython, verbose > False, classifierOutput > "real", classifierInput > "pattern"}
Regression problems are solved similarly, through svmRegression
:
In[8]:= regressor = svmRegression[pattern, label, kernel > {"Gaussian", 0.4}]; In[9]:= grRegressor = Plot[regressor, {x, 0, 1}, PlotRange > All, AspectRatio > 1/GoldenRatio, Frame > True]; In[10]:= Show[grRegrPoints,grRegressor]
svMathematica is licensed uder the LGPL license.