Changeset 9612:4a74a19879a1 in orange


Ignore:
Timestamp:
02/02/12 15:17:37 (2 years ago)
Author:
Lan Zagar <lan.zagar@…>
Branch:
default
Message:

PLS documentation updated.

Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/regression/pls.py

    r9562 r9612  
    1010Implementation is based on `Scikit learn python implementation`_ 
    1111 
    12 Example :: 
    13  
    14     >>> import Orange 
    15     >>> from Orange.regression import pls 
    16     >>> data = Orange.data.Table("test-pls.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     >>>  
     12Example 
     13------- 
     14 
     15The following code shows how to fit a PLS regression model on a multi-target data set. 
     16 
     17.. literalinclude:: code/pls-example.py 
     18 
     19Output :: 
     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 
    3738 
    3839.. autoclass:: PLSRegressionLearner 
     
    215216 
    216217        :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            single-target regression learner is constructed. Otherwise a 
     224            multi-target learner predicting response variables defined by 
     225            :obj:`~Orange.data.Domain.class_vars` is constructed. 
    222226        :type x_vars, y_vars: list             
    223227 
     
    444448        """        
    445449        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)] 
    448452        lines = [fmt % tuple([x_vars[i]] + list(coef)) 
    449453                 for i, coef in enumerate(self.coefs)] 
     
    483487    from Orange.regression import pls 
    484488 
    485     data = Orange.data.Table("test-pls.tab") 
     489    data = Orange.data.Table("multitarget-synthetic") 
    486490    l = pls.PLSRegressionLearner() 
    487491 
Note: See TracChangeset for help on using the changeset viewer.