[Scipy-svn] r2144 - in trunk/Lib/sandbox/svm: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Thu Aug 3 10:12:32 CDT 2006


Author: fullung
Date: 2006-08-03 10:12:13 -0500 (Thu, 03 Aug 2006)
New Revision: 2144

Modified:
   trunk/Lib/sandbox/svm/dataset.py
   trunk/Lib/sandbox/svm/tests/test_classification.py
   trunk/Lib/sandbox/svm/tests/test_dataset.py
   trunk/Lib/sandbox/svm/tests/test_regression.py
Log:
Move zipping inside the datasets.


Modified: trunk/Lib/sandbox/svm/dataset.py
===================================================================
--- trunk/Lib/sandbox/svm/dataset.py	2006-08-03 14:38:13 UTC (rev 2143)
+++ trunk/Lib/sandbox/svm/dataset.py	2006-08-03 15:12:13 UTC (rev 2144)
@@ -139,22 +139,20 @@
         param.kernel_type = libsvm.PRECOMPUTED
 
 class LibSvmRegressionDataSet(LibSvmDataSet):
-    def __init__(self, origdata):
-        data = map(lambda x: (x[0], convert_to_svm_node(x[1])), origdata)
+    def __init__(self, y, x):
+        origdata = zip(y, x)
+        data = [(x[0], convert_to_svm_node(x[1])) for x in origdata]
         LibSvmDataSet.__init__(self, data)
 
 class LibSvmClassificationDataSet(LibSvmDataSet):
-    def __init__(self, origdata):
-        labels = N.array(map(lambda x: x[0], origdata), dtype=N.intc)
-        labels.sort()
-        self.labels = labels
-
-        data = map(lambda x: (x[0],convert_to_svm_node(x[1])), origdata)
+    def __init__(self, labels, x):
+        origdata = zip(labels, x)
+        data = [(x[0], convert_to_svm_node(x[1])) for x in origdata]
         LibSvmDataSet.__init__(self, data)
 
 class LibSvmOneClassDataSet(LibSvmDataSet):
-    def __init__(self, origdata):
-        data = map(lambda x: tuple([0,convert_to_svm_node(x)]), origdata)
+    def __init__(self, x):
+        data = [(0, convert_to_svm_node(y)) for y in x]
         LibSvmDataSet.__init__(self, data)
 
 class LibSvmTestDataSet:

Modified: trunk/Lib/sandbox/svm/tests/test_classification.py
===================================================================
--- trunk/Lib/sandbox/svm/tests/test_classification.py	2006-08-03 14:38:13 UTC (rev 2143)
+++ trunk/Lib/sandbox/svm/tests/test_classification.py	2006-08-03 15:12:13 UTC (rev 2144)
@@ -32,7 +32,7 @@
              N.array([0, 1]),
              N.array([1, 0]),
              N.array([1, 1])]
-        traindata = LibSvmClassificationDataSet(zip(labels, x))
+        traindata = LibSvmClassificationDataSet(labels, x)
         testdata = LibSvmTestDataSet(x)
         return traindata, testdata
 
@@ -100,7 +100,7 @@
     def check_cross_validate(self):
         labels = ([-1] * 50) + ([1] * 50)
         x = N.random.randn(len(labels), 10)
-        traindata = LibSvmClassificationDataSet(zip(labels, x))
+        traindata = LibSvmClassificationDataSet(labels, x)
         kernel = LinearKernel()
         model = LibSvmCClassificationModel(kernel)
         nr_fold = 10
@@ -133,11 +133,11 @@
         x1 = N.random.randn(len(labels1), 10)
         labels2 = N.random.random_integers(0, 2, 10)
         x2 = N.random.randn(len(labels2), x1.shape[1])
-        trndata1 = LibSvmClassificationDataSet(zip(labels1, x1))
-        trndata2 = LibSvmClassificationDataSet(zip(labels2, x2))
+        trndata1 = LibSvmClassificationDataSet(labels1, x1)
+        trndata2 = LibSvmClassificationDataSet(labels2, x2)
         reflabels = N.concatenate([labels1, labels2])
         refx = N.vstack([x1, x2])
-        trndata = LibSvmClassificationDataSet(zip(reflabels, refx))
+        trndata = LibSvmClassificationDataSet(reflabels, refx)
         testdata = LibSvmTestDataSet(refx)
         return trndata, testdata, trndata1, trndata2
 

Modified: trunk/Lib/sandbox/svm/tests/test_dataset.py
===================================================================
--- trunk/Lib/sandbox/svm/tests/test_dataset.py	2006-08-03 14:38:13 UTC (rev 2143)
+++ trunk/Lib/sandbox/svm/tests/test_dataset.py	2006-08-03 15:12:13 UTC (rev 2144)
@@ -93,7 +93,7 @@
             ]
         y = N.random.randn(10)
         x = N.random.randn(len(y), 10)
-        origdata = LibSvmRegressionDataSet(zip(y, x))
+        origdata = LibSvmRegressionDataSet(y, x)
 
         for kernel in kernels:
             # calculate expected Gram matrix
@@ -112,12 +112,12 @@
 
         y1 = N.random.randn(10)
         x1 = N.random.randn(len(y1), 10)
-        origdata = LibSvmRegressionDataSet(zip(y1, x1))
+        origdata = LibSvmRegressionDataSet(y1, x1)
         pcdata = origdata.precompute(kernel)
 
         y2 = N.random.randn(5)
         x2 = N.random.randn(len(y2), x1.shape[1])
-        moredata = LibSvmRegressionDataSet(zip(y2, x2))
+        moredata = LibSvmRegressionDataSet(y2, x2)
         morepcdata = pcdata.combine(moredata)
 
         expt_grammat = N.empty((len(y1) + len(y2),)*2)

Modified: trunk/Lib/sandbox/svm/tests/test_regression.py
===================================================================
--- trunk/Lib/sandbox/svm/tests/test_regression.py	2006-08-03 14:38:13 UTC (rev 2143)
+++ trunk/Lib/sandbox/svm/tests/test_regression.py	2006-08-03 15:12:13 UTC (rev 2144)
@@ -32,7 +32,7 @@
              N.array([0, 1]),
              N.array([1, 0]),
              N.array([1, 1])]
-        traindata = LibSvmRegressionDataSet(zip(y, x))
+        traindata = LibSvmRegressionDataSet(y, x)
         testdata = LibSvmTestDataSet(x)
         model = ModelType(LinearKernel(), probability=True)
         results = model.fit(traindata)
@@ -45,7 +45,7 @@
              N.array([0, 1]),
              N.array([1, 0]),
              N.array([1, 1])]
-        traindata = LibSvmRegressionDataSet(zip(labels, x))
+        traindata = LibSvmRegressionDataSet(labels, x)
         testdata = LibSvmTestDataSet(x)
         return traindata, testdata
 
@@ -85,7 +85,7 @@
     def check_cross_validate(self):
         y = N.random.randn(100)
         x = N.random.randn(len(y), 10)
-        traindata = LibSvmRegressionDataSet(zip(y, x))
+        traindata = LibSvmRegressionDataSet(y, x)
         kernel = LinearKernel()
         model = LibSvmEpsilonRegressionModel(kernel)
         nr_fold = 10
@@ -108,11 +108,11 @@
         x1 = N.random.randn(len(y1), 10)
         y2 = N.random.randn(5)
         x2 = N.random.randn(len(y2), x1.shape[1])
-        trndata1 = LibSvmRegressionDataSet(zip(y1, x1))
-        trndata2 = LibSvmRegressionDataSet(zip(y2, x2))
+        trndata1 = LibSvmRegressionDataSet(y1, x1)
+        trndata2 = LibSvmRegressionDataSet(y2, x2)
         refy = N.concatenate([y1, y2])
         refx = N.vstack([x1, x2])
-        trndata = LibSvmRegressionDataSet(zip(refy, refx))
+        trndata = LibSvmRegressionDataSet(refy, refx)
         testdata = LibSvmTestDataSet(refx)
         return trndata, trndata1, trndata2, testdata
 



More information about the Scipy-svn mailing list