Commits

Aleš Erjavec committed cadf424

PLS learner/predictor fix. Added tests.

Comments (0)

Files changed (2)

Orange/regression/pls.py

 
         """     
         domain = table.domain
+        multitarget = False
         if x_vars is None and y_vars is None:
             # Response variables are defined in the table.
             x_vars = domain.features
                 y_vars = [domain.class_var]
             elif domain.class_vars:
                 y_vars = domain.class_vars
+                multitarget = True
             else:
                 raise TypeError('Class-less domain (x-vars and y-vars needed).')
-            x_table = select_attrs(table, x_vars)
-            y_table = select_attrs(table, y_vars)
+
         elif not (x_vars and y_vars):
             raise ValueError("Both x_vars and y_vars must be defined.")
+        else:
+            multitarget = True
 
         x_table = select_attrs(table, x_vars)
         y_table = select_attrs(table, y_vars)
         y_vars = list(y_table.domain.variables)
         
         domain = Orange.data.Domain(x_vars + y_vars, False)
-        multitarget = True if len(y_vars) > 1 else False
 
         x = x_table.to_numpy()[0]
         y = y_table.to_numpy()[0]
                  mu_x=None, mu_y=None, x_vars=None, y_vars=None, **kwargs):
         self.domain = domain
         self.multitarget = multitarget
+        if multitarget and y_vars:
+            self.class_vars = y_vars
+        elif y_vars:
+            self.class_var = y_vars[0]
+
         self.coefs = coefs
         self.mu_x, self.mu_y = mu_x, mu_y
         self.sigma_x, self.sigma_y = sigma_x, sigma_y

Orange/testing/unit/tests/test_pls.py

+try:
+    import unittest2 as unittest
+except:
+    import unittest
+
+
+from Orange.testing import testing
+from Orange.regression import pls
+
+
+@testing.datasets_driven(datasets=testing.REGRESSION_DATASETS)
+class TestPLS(testing.LearnerTestCase):
+    LEARNER = pls.PLSRegressionLearner
+
+
+# TODO: Test the PLS by passing x_vars, y_vars