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 |
Uses the classifier induced by Orange.multitarget.psl.PLSClassificationLearner.
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)
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
A deprecated member ‘deflationMode’. Use ‘deflation_mode’ instead.
Fit all unknown parameters, i.e. weights, scores, loadings (for x and y) and regression coefficients. Return a dict with all of the parameters.
A deprecated member ‘maxIter’. Use ‘max_iter’ instead.
A deprecated member ‘nComp’. Use ‘n_comp’ instead.
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
A n x n_comp numpy array of x-scores
A n x n_comp numpy array of y-scores
A p x n_comp numpy array of x-weights
A q x n_comp numpy array of y-weights
A p x n_comp numpy array of x-loadings
A q x n_comp numpy array of y-loading
A p x q numpy array coefficients of the linear model: Y = X coefs + E
Predictor variables
Response variables
A deprecated member ‘muX’. Use ‘mu_x’ instead.
A deprecated member ‘muY’. Use ‘mu_y’ instead.
A deprecated member ‘sigmaX’. Use ‘sigma_x’ instead.
A deprecated member ‘sigmaY’. Use ‘sigma_y’ instead.
Pretty-prints the coefficient of the PLS regression model.
A deprecated member ‘xVars’. Use ‘x_vars’ instead.
A deprecated member ‘yVars’. Use ‘y_vars’ instead.
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 |
---|
NIPALS algorithm; returns the first left and rigth singular vectors of X’Y.
Parameters: |
---|
Return the first left and right singular vectors of X’Y.
Parameters: | Y (X,) – data matrix |
---|
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.
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])