PLS Classification Learner (pls)

class Orange.multitarget.pls.PLSClassificationLearner

Bases: Orange.classification.Learner

Expands and wraps Orange.regression.PLSRegressionLearner to support classification. Multi-classes are expanded with Orange.data.continuization.DomainContinuizer.

Return type:Orange.multitarget.psl.PLSClassifier or
Return type:Orange.multitarget.psl.PLSClassificationLearner
class Orange.multitarget.pls.PLSClassifier(**kwargs)

Uses the classifier induced by Orange.multitarget.psl.PLSClassificationLearner.

PLS Regression Learner

Partial least sqaures regression (PLS)

Partial least squares regression is a statistical method for simultaneous prediction of multiple response variables. Orange’s implementation is based on Scikit learn python implementation.

The following code shows how to fit a PLS regression model on a multi-target data set.

import Orange
data = Orange.data.Table("multitarget-synthetic.tab")
learner = Orange.multitarget.pls.PLSRegressionLearner()
classifier = learner(data)
class Orange.regression.pls.PLSRegressionLearner(*args, **kwargs)

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 Orange.regression.base.BaseRegressionLearner that is used for preprocessing the data (continuization and imputation) before fitting the regression parameters

deflationMode

A deprecated member ‘deflationMode’. Use ‘deflation_mode’ instead.

fit(X, Y)

Fit all unknown parameters, i.e. weights, scores, loadings (for x and y) and regression coefficients. Return a dict with all of the parameters.

maxIter

A deprecated member ‘maxIter’. Use ‘max_iter’ instead.

nComp

A deprecated member ‘nComp’. Use ‘n_comp’ instead.

class Orange.regression.pls.PLSRegression(*args, **kwargs)

Predict values of the response variables based on the values of independent variables.

Basic notations: n - number of data instances p - number of independent variables q - number of reponse variables

T

A n x n_comp numpy array of x-scores

U

A n x n_comp numpy array of y-scores

W

A p x n_comp numpy array of x-weights

C

A q x n_comp numpy array of y-weights

P

A p x n_comp numpy array of x-loadings

Q

A q x n_comp numpy array of y-loading

coefs

A p x q numpy array coefficients of the linear model: Y = X coefs + E

x_vars

Predictor variables

y_vars

Response variables

muX

A deprecated member ‘muX’. Use ‘mu_x’ instead.

muY

A deprecated member ‘muY’. Use ‘mu_y’ instead.

sigmaX

A deprecated member ‘sigmaX’. Use ‘sigma_x’ instead.

sigmaY

A deprecated member ‘sigmaY’. Use ‘sigma_y’ instead.

to_string()

Pretty-prints the coefficient of the PLS regression model.

xVars

A deprecated member ‘xVars’. Use ‘x_vars’ instead.

yVars

A deprecated member ‘yVars’. Use ‘y_vars’ instead.

Utility functions

Orange.regression.pls.normalize_matrix(X)

Normalize a matrix column-wise: subtract the means and divide by standard deviations. Returns the standardized matrix, sample mean and standard deviation

Parameters:X (numpy.array) – data matrix
Orange.regression.pls.nipals_xy(*args, **kwargs)

NIPALS algorithm; returns the first left and rigth singular vectors of X’Y.

Parameters:
  • Y (X,) – data matrix
  • mode (string) – possible values “PLS” (default) or “CCA”
  • max_iter (int) – maximal number of iterations (default: 500)
  • tol (a not negative float) – tolerance parameter; if norm of difference between two successive left singular vectors is less than tol, iteration is stopped
Orange.regression.pls.svd_xy(X, Y)

Return the first left and right singular vectors of X’Y.

Parameters:Y (X,) – data matrix

Examples

The following code predicts the values of output variables for the first two instances in data.

print "Prediction for the first 2 data instances: \n" 
for d in data[:2]:
    print "Actual    ", d.get_classes()
    print "Predicted ", classifier(d)
    print 
Actual     [<orange.Value 'Y1'='0.490'>, <orange.Value 'Y2'='1.237'>, <orange.Value 'Y3'='1.808'>, <orange.Value 'Y4'='0.422'>]
Predicted  [<orange.Value 'Y1'='0.613'>, <orange.Value 'Y2'='0.826'>, <orange.Value 'Y3'='1.084'>, <orange.Value 'Y4'='0.534'>]

Actual     [<orange.Value 'Y1'='0.167'>, <orange.Value 'Y2'='-0.664'>, <orange.Value 'Y3'='-1.378'>, <orange.Value 'Y4'='0.589'>]
Predicted  [<orange.Value 'Y1'='0.058'>, <orange.Value 'Y2'='-0.706'>, <orange.Value 'Y3'='-1.420'>, <orange.Value 'Y4'='0.599'>]

To see the coefficient of the model, print the model:

print 'Regression coefficients:\n', classifier    
Regression coefficients:
                   Y1           Y2           Y3           Y4
      X1        0.714        2.153        3.590       -0.078 
      X2       -0.238       -2.500       -4.797       -0.036 
      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.

Examples

import Orange

l1 = Orange.multitarget.pls.PLSClassificationLearner(n_mid=15, reg_fact=0.1, max_iter=100, name="PLS")
l2 = Orange.multitarget.binary.BinaryRelevanceLearner(
	learner = Orange.classification.majority.MajorityLearner, name = "Majority")
learners = [l1, l2]

data = Orange.data.Table('multitarget:flare.tab')

results = Orange.evaluation.testing.cross_validation(learners, data, 3)

print "Classification - flare.tab"
print "%18s  %6s  %8s  %8s" % ("Learner    ", "LogLoss", "Mean Acc", "Glob Acc")
for i in range(len(learners)):
    print "%18s  %1.4f    %1.4f    %1.4f" % (learners[i].name,
    Orange.multitarget.scoring.mt_average_score(results, Orange.evaluation.scoring.logloss)[i],
    Orange.multitarget.scoring.mt_mean_accuracy(results)[i],
    Orange.multitarget.scoring.mt_global_accuracy(results)[i])

# REGRESSION
l1 = Orange.multitarget.pls.PLSRegressionLearner(name="PLS")
l2 = Orange.multitarget.binary.BinaryRelevanceLearner(
	learner = Orange.regression.mean.MeanLearner, name = "Majority")
learners = [l1, l2]
# PLSClassifier do not work with missing values, the missing values need to be imputed
data = Orange.data.Table('multitarget-synthetic')

results = Orange.evaluation.testing.cross_validation(learners, data, 3)

print "Regression - multitarget-synthetic.tab"
print "%18s  %6s" % ("Learner    ", "RMSE")
for i in range(len(learners)):
    print "%18s  %1.4f" % (learners[i].name,
    Orange.multitarget.scoring.mt_average_score(results, Orange.evaluation.scoring.RMSE)[i])