Changeset 9612:4a74a19879a1 in orange for orange/Orange/regression/pls.py
 Timestamp:
 02/02/12 15:17:37 (2 years ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/Orange/regression/pls.py
r9562 r9612 10 10 Implementation is based on `Scikit learn python implementation`_ 11 11 12 Example :: 13 14 >>> import Orange 15 >>> from Orange.regression import pls 16 >>> data = Orange.data.Table("testpls.tab") 17 >>> # set independent and response variables 18 >>> x = data.domain.features 19 >>> y = data.domain.class_vars 20 >>> print x 21 [FloatVariable 'X1', FloatVariable 'X2', FloatVariable 'X3'] 22 >>> print y 23 [FloatVariable 'Y1', FloatVariable 'Y2', FloatVariable 'Y3', FloatVariable 'Y4'] 24 >>> # The information which variables are independent and which are responses 25 >>> # can be provided in the data definition. 26 >>> # If a variable var has key "label" in dictionary Orange.data.Domain[var].attributes 27 >>> # it is considered as a response variable. 28 >>> # In such situation x and y do not need to be specified. 29 >>> l = pls.PLSRegressionLearner() 30 >>> c = l(data, x_vars=x, y_vars=y) 31 >>> print c 32 Y1 Y2 Y3 Y4 33 X1 0.513 0.915 0.341 0.069 34 X2 0.641 1.044 0.249 0.015 35 X3 1.393 0.050 0.729 0.108 36 >>> 12 Example 13  14 15 The following code shows how to fit a PLS regression model on a multitarget data set. 16 17 .. literalinclude:: code/plsexample.py 18 19 Output :: 20 21 Input variables: <FloatVariable 'X1', FloatVariable 'X2', FloatVariable 'X3'> 22 Response variables: <FloatVariable 'Y1', FloatVariable 'Y2', FloatVariable 'Y3', FloatVariable 'Y4'> 23 Prediction for the first 2 data instances: 24 25 Actual [<orange.Value 'Y1'='0.490'>, <orange.Value 'Y2'='1.237'>, <orange.Value 'Y3'='1.808'>, <orange.Value 'Y4'='0.422'>] 26 Predicted [<orange.Value 'Y1'='0.613'>, <orange.Value 'Y2'='0.826'>, <orange.Value 'Y3'='1.084'>, <orange.Value 'Y4'='0.534'>] 27 28 Actual [<orange.Value 'Y1'='0.167'>, <orange.Value 'Y2'='0.664'>, <orange.Value 'Y3'='1.378'>, <orange.Value 'Y4'='0.589'>] 29 Predicted [<orange.Value 'Y1'='0.058'>, <orange.Value 'Y2'='0.706'>, <orange.Value 'Y3'='1.420'>, <orange.Value 'Y4'='0.599'>] 30 31 Regression coefficients: 32 Y1 Y2 Y3 Y4 33 X1 0.714 2.153 3.590 0.078 34 X2 0.238 2.500 4.797 0.036 35 X3 0.230 0.314 0.880 0.060 36 37 37 38 38 39 .. autoclass:: PLSRegressionLearner … … 215 216 216 217 :param x_vars, y_vars: List of input and response variables 217 (`Orange.data.variable.Continuous` or `Orange.data.variable.Discrete`). 218 If None (default) it is assumed that data definition provides information 219 which variables are reponses and which not. If a variable var 220 has key "label" in dictionary Orange.data.Domain[var].attributes 221 it is treated as a response variable 218 (:obj:`Orange.data.variable.Continuous` or 219 :obj:`Orange.data.variable.Discrete`). If None (default) it is 220 assumed that the data domain provides information which variables 221 are reponses and which are not. If data has 222 :obj:`~Orange.data.Domain.class_var` defined in its domain, a 223 singletarget regression learner is constructed. Otherwise a 224 multitarget learner predicting response variables defined by 225 :obj:`~Orange.data.Domain.class_vars` is constructed. 222 226 :type x_vars, y_vars: list 223 227 … … 444 448 """ 445 449 x_vars, y_vars = [x.name for x in self.x_vars], [y.name for y in self.y_vars] 446 fmt = "% 6s " + "%5.3f" * len(y_vars)447 first = [" " * 7 + "%6s" * len(y_vars) % tuple(y_vars)]450 fmt = "%8s " + "%12.3f " * len(y_vars) 451 first = [" " * 8 + "%13s" * len(y_vars) % tuple(y_vars)] 448 452 lines = [fmt % tuple([x_vars[i]] + list(coef)) 449 453 for i, coef in enumerate(self.coefs)] … … 483 487 from Orange.regression import pls 484 488 485 data = Orange.data.Table(" testpls.tab")489 data = Orange.data.Table("multitargetsynthetic") 486 490 l = pls.PLSRegressionLearner() 487 491
Note: See TracChangeset
for help on using the changeset viewer.