# Changeset 10420:969093619068 in orange for Orange/regression/pls.py

Ignore:
Timestamp:
03/02/12 15:47:18 (21 months ago)
Branch:
default
Message:

Minor changes to documentation about multitarget

File:
1 edited

Unmodified
Removed
• ## Orange/regression/pls.py

 r10367 `Partial least squares `_ regression is a statistical method which can be used to predict multiple response variables simultaniously. Implementation is based on `Scikit learn python implementation regression is a statistical method for simultaneous prediction of multiple response variables. Orange's implementation is based on `Scikit learn python implementation `_. .. autofunction:: svd_xy ======== ======== To predict values for the first two data instances use the following code: The following code predicts the values of output variables for the first two instances in ``data``. .. literalinclude:: code/pls-example.py :lines: 16-20 Output:: :: Actual     [, , , ] Predicted  [, , , ] To see the coefficient of the model (in this case they are stored in a matrix) print the model: To see the coefficient of the model, print the model: .. literalinclude:: code/pls-example.py :lines: 22 The ouptut looks like this:: :: Regression coefficients: X3        0.230       -0.314       -0.880       -0.060 Note that coefficients are stored in a matrix since the model predicts values of multiple outputs. """ def normalize_matrix(X): """ Normalizes matrix, i.e. subtracts column means and divides them by column standard deviations. Returns the standardized matrix, sample mean and standard deviation """ Normalize a matrix column-wise: subtract the means and divide by standard deviations. Returns the standardized matrix, sample mean and standard deviation :param X: data matrix def nipals_xy(X, Y, mode="PLS", max_iter=500, tol=1e-06): """ NIPALS algorithm. Returns the first left and rigth singular NIPALS algorithm; returns the first left and rigth singular vectors of X'Y. :type mode: string :param max_iter: maximal number of iterations (default 500) :param max_iter: maximal number of iterations (default: 500) :type max_iter: int :param tol: tolerance parameter, if norm of difference :param tol: tolerance parameter; if norm of difference between two successive left singular vectors is less than tol, iteration is stopped def svd_xy(X, Y): """ Returns the first left and right singular """ Return the first left and right singular vectors of X'Y. def select_attrs(table, attributes, class_var=None, metas=None): """ Select only ``attributes`` from the ``table``. """ Select ``attributes`` from the ``table`` and return a new data table. """ domain = Orange.data.Domain(attributes, class_var) class PLSRegressionLearner(base.BaseRegressionLearner): """ Fits the partial least squares regression model, i.e. learns the regression parameters. The implementation is based on `Scikit learn python implementation`_ """ Fit the partial least squares regression model, i.e. learn the regression parameters. The implementation is based on `Scikit learn python implementation`_ The class is derived from :class:`Orange.regression.base.BaseRegressionLearner` which is used for preprocessing the data (continuization and imputation) :class:`Orange.regression.base.BaseRegressionLearner` that is used for preprocessing the data (continuization and imputation) before fitting the regression parameters .. attribute:: n_comp number of components to keep. Default: 2 number of components to keep (default: 2) .. attribute:: deflation_mode .. attribute:: algorithm The algorithm used to estimate the weights: The algorithm for estimating the weights: "nipals" or "svd" (default) :param x_vars, y_vars: List of input and response variables (:obj:`Orange.feature.Continuous` or :obj:`Orange.feature.Discrete`). If None (default) it is :obj:`Orange.feature.Discrete`). If ``None`` (default) it is assumed that the data domain provides information which variables are reponses and which are not. If data has def fit(self, X, Y): """ Fits all unknown parameters, i.e. """ Fit all unknown parameters, i.e. weights, scores, loadings (for x and y) and regression coefficients. Returns a dict with all of the parameters. Return a dict with all of the parameters. """ # copy since this will contain the residuals (deflated) matrices class PLSRegression(Orange.classification.Classifier): """ PLSRegression predicts value of the response variables """ Predict values of the response variables based on the values of independent variables.
Note: See TracChangeset for help on using the changeset viewer.