import numpy as np
from sklearn.cross_decomposition import PLSCanonical
X = np.array([[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]])
Y = np.array([[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]])
plsca = PLSCanonical(n_components=2)
plsca.fit(X, Y)
# Predict targets of given samples
plsca.predict(X[:2, :])
# Dimensional reduction
X_c, Y_c = plsca.transform(X, Y)
# Transform data back to its original space
plsca.inverse_transform(X_c)
plsca.coef_
from sklearn.cross_decomposition import PLSSVD
pls = PLSSVD(n_components=2).fit(X, Y)
plsca.predict(X[:2, :])
X_c, Y_c = pls.transform(X, Y)
X_c, Y_c
from sklearn.cross_decomposition import PLSRegression
pls2 = PLSRegression(n_components=2)
pls2.fit(X, Y)
pls2.predict(X[:2, :])
from sklearn.cross_decomposition import CCA
cca = CCA(n_components=2)
cca.fit(X, Y)
cca.predict(X[:2, :])
X_c, Y_c = cca.transform(X, Y)
X_c, Y_c