'Fit model to data.
Parameters
X : array-like, shape = [n_samples, n_features]
Training vectors, where n_samples is the number of samples and
n_features is the number of predictors.
Y : array-like, shape = [n_samples, n_targets]
Target vectors, where n_samples is the number of samples and
n_targets is the number of response variables.'

def fit(self, X, Y):

    check_consistent_length(X, Y)
    X = check_array(X, dtype=np.float64, copy=self.copy)
    Y = check_array(Y, dtype=np.float64, copy=self.copy, ensure_2d=False)
    if (Y.ndim == 1):
        Y = Y.reshape((-1), 1)
    if (self.n_components > max(Y.shape[1], X.shape[1])):
        raise ValueError(('Invalid    number    of    components    n_components=%d    with    X    of    shape    %s    and    Y    of    shape    %s.' % (self.n_components, str(X.shape), str(Y.shape))))
    (X, Y, self.x_mean_, self.y_mean_, self.x_std_, self.y_std_) = _center_scale_xy(X, Y, self.scale)
    C = np.dot(X.T, Y)
    if (self.n_components >= np.min(C.shape)):
        (U, s, V) = svd(C, full_matrices=False)
    else:
        (U, s, V) = svds(C, k=self.n_components)
    (U, V) = svd_flip(U, V)
    V = V.T
    self.x_scores_ = np.dot(X, U)
    self.y_scores_ = np.dot(Y, V)
    self.x_weights_ = U
    self.y_weights_ = V
    return self
