[Scipy-svn] r2192 - trunk/Lib/sandbox/svm

scipy-svn at scipy.org scipy-svn at scipy.org
Fri Sep 8 05:41:05 CDT 2006


Author: fullung
Date: 2006-09-08 05:40:47 -0500 (Fri, 08 Sep 2006)
New Revision: 2192

Modified:
   trunk/Lib/sandbox/svm/__init__.py
   trunk/Lib/sandbox/svm/kernel.py
Log:
Documentation.


Modified: trunk/Lib/sandbox/svm/__init__.py
===================================================================
--- trunk/Lib/sandbox/svm/__init__.py	2006-09-06 00:46:12 UTC (rev 2191)
+++ trunk/Lib/sandbox/svm/__init__.py	2006-09-08 10:40:47 UTC (rev 2192)
@@ -1,18 +1,62 @@
 """
 A Support Vector Machine, this module defines the following classes:
 
-- `CSVCModel`, a model for C-SV classification
-- `NuSVCModel`, a model for nu-SV classification
-- `EpsilonSVRModel`, a model for epsilon-SV regression
-- `NuSVRModel`, a model for nu-SV regression
-- `OneClassModel`, a model for distribution estimation (one-class SVM)
+- `LibSvmCClassificationModel`, a model for C-SV classification
+- `LibSvmNuClassificationModel`, a model for nu-SV classification
+- `LibSvmEpsilonRegressionModel`, a model for epsilon-SV regression
+- `LibSvmNuRegressionModel`, a model for nu-SV regression
+- `LibSvmOneClassModel`, a model for distribution estimation
+  (one-class SVM)
 
+Kernel classes:
 
+- `LinearKernel`, a linear kernel
+- `PolynomialKernel`, a polynomial kernel
+- `RBFKernel`, a radial basis function kernel
+- `SigmoidKernel`, a sigmoid kernel
+- `CustomKernel`, a kernel that wraps any callable
+
+Dataset classes:
+
+- `LibSvmClassificationDataSet`, a dataset for training classification
+  models
+- `LibSvmRegressionDataSet`, a dataset for training regression models
+- `LibSvmOneClassDataSet`, a dataset for training distribution
+  estimation (one-class SVM) models
+- `LibSvmTestDataSet`, a dataset for testing with any model
+
+Data type classes:
+
+- `svm_node_dtype`, the libsvm data type for its arrays
+
 How To Use This Module
 ======================
 (See the individual classes, methods, and attributes for details.)
 
 1. Import it: ``import svm`` or ``from svm import ...``.
+
+2. Create a training dataset for your problem::
+
+       traindata = LibSvmClassificationDataSet(labels, x)
+       traindata = LibSvmRegressionDataSet(y, x)
+       traindata = LibSvmOneClassDataSet(x)
+
+   where x is sequence of NumPy arrays containing scalars or
+   svm_node_dtype entries.
+
+3. Create a test dataset::
+
+       testdata = LibSvmTestDataSet(u)
+
+4. Create a model and fit it to the training data::
+
+       model = LibSvmCClassificationModel(kernel)
+       results = model.fit(traindata)
+
+5. Use the results to make predictions with the test data::
+
+       p = results.predict(testdata)
+       v = results.predict_values(testdata)
 """
 
 from classification import *

Modified: trunk/Lib/sandbox/svm/kernel.py
===================================================================
--- trunk/Lib/sandbox/svm/kernel.py	2006-09-06 00:46:12 UTC (rev 2191)
+++ trunk/Lib/sandbox/svm/kernel.py	2006-09-08 10:40:47 UTC (rev 2192)
@@ -11,6 +11,7 @@
     ]
 
 class LinearKernel:
+    """Linear kernel: u'*v."""
     def __init__(self):
         self.kernel_type = libsvm.LINEAR
 
@@ -23,6 +24,8 @@
         return self
 
 class PolynomialKernel:
+    """Polynomial kernel: (gamma*u'*v + coef0)^degree."""
+
     def __init__(self, degree, gamma, coef0):
         self.kernel_type = libsvm.POLY
         self.degree = degree
@@ -51,6 +54,8 @@
             'model compaction for PolynomialKernel not implemented'
 
 class RBFKernel:
+    """Radial basis function kernel: exp(-gamma*|u-v|^2)"""
+
     def __init__(self, gamma):
         self.kernel_type = libsvm.RBF
         self.gamma = gamma
@@ -75,6 +80,8 @@
             'model compaction for RBFKernel not implemented'
 
 class SigmoidKernel:
+    """Sigmoid kernel: tanh(gamma*u'*v + coef0)"""
+
     def __init__(self, gamma, coef0):
         self.kernel_type = libsvm.SIGMOID
         self.gamma = gamma
@@ -94,6 +101,8 @@
             'model compaction for SigmoidKernel not implemented'
 
 class CustomKernel:
+    """Custom kernel: any callable"""
+
     def __init__(self, f):
         self.kernel_type = libsvm.PRECOMPUTED
         self.f = f



More information about the Scipy-svn mailing list