def transform(self, x=None, y=None):
        """

        Calculate the scores for a data block from the original data. Equivalent to sklearn's TransformerMixin method.

        :param x: Data matrix to fit the PLS model.
        :type x: numpy.ndarray, shape [n_samples, n_features] or None
        :param y: Data matrix to fit the PLS model.
        :type y: numpy.ndarray, shape [n_samples, n_features] or None
        :return: Latent Variable scores (T) for the X matrix and for the Y vector/matrix (U).
        :rtype: tuple with 2 numpy.ndarray, shape [n_samples, n_comps]
        :raise ValueError: If dimensions of input data are mismatched.
        :raise AttributeError: When calling the method before the model is fitted.
        """

        try:
            # Check if model is fitted
            if self._isfitted is True:
                # If X and Y are passed, complain and do nothing
                if (x is not None) and (y is not None):
                    raise ValueError('xx')
                # If nothing is passed at all, complain and do nothing
                elif (x is None) and (y is None):
                    raise ValueError('yy')
                # If Y is given, return U
                elif x is None:
                    # The y variable expected is a single vector with ints as class label - binary
                    # and multiclass classification are allowed but not multilabel so this will work.
                    #if y.ndim != 1:
                    #    raise TypeError('Please supply a dummy vector with integer as class membership')
                    # Previously fitted model will already have the number of classes
                    if self.n_classes <= 2:
                        y = self.y_scaler.transform(y)
                    else:
                        # The dummy matrix is created here manually because its possible for the model to be fitted to
                        # a larger number of classes than what is being passed in transform
                        # and other methods post-fitting
                        # If matrix is not dummy, generate the dummy accordingly
                        if y.ndim ==1:
                            dummy_matrix = np.zeros((len(y), self.n_classes))
                            for col in range(self.n_classes):
                                dummy_matrix[np.where(y == col), col] = 1
                            y = self.y_scaler.transform(dummy_matrix)
                    # Taking advantage of rotations_y
                    # Otherwise this would be the full calculation U = Y*pinv(CQ')*C
                    U = np.dot(y, self.rotations_cs)
                    return U

                # If X is given, return T
                elif y is None:
                    # Comply with the sklearn scaler behaviour and X scaling - business as usual
                    if x.ndim == 1:
                        x = x.reshape(-1, 1)
                    xscaled = self.x_scaler.transform(x)
                    # Taking advantage of the rotation_x
                    # Otherwise this would be would the full calculation T = X*pinv(WP')*W
                    T = np.dot(xscaled, self.rotations_ws)
                    return T
            else:
                raise AttributeError('Model not fitted')
        except ValueError as verr:
            raise verr
        except AttributeError as atter:
            raise atter
def transform ( self , x = None , y = None ) : try : if self . _isfitted is True : if ( x is not None ) and ( y is not None ) : raise ValueError ( 'xx' ) elif ( x is None ) and ( y is None ) : raise ValueError ( 'yy' ) elif x is None : if self . n_classes <= 2 : y = self . y_scaler . transform ( y ) else : if y . ndim == 1 : dummy_matrix = np . zeros ( ( len ( y ) , self . n_classes ) ) for col in range ( self . n_classes ) : dummy_matrix [ np . where ( y == col ) , col ] = 1 y = self . y_scaler . transform ( dummy_matrix ) U = np . dot ( y , self . rotations_cs ) return U elif y is None : if x . ndim == 1 : x = x . reshape ( - 1 , 1 ) xscaled = self . x_scaler . transform ( x ) T = np . dot ( xscaled , self . rotations_ws ) return T else : raise AttributeError ( 'Model not fitted' ) except ValueError as verr : raise verr except AttributeError as atter : raise atter
Calculate the scores for a data block from the original data. Equivalent to sklearn's TransformerMixin method.

        :param x: Data matrix to fit the PLS model.
        :type x: numpy.ndarray, shape [n_samples, n_features] or None
        :param y: Data matrix to fit the PLS model.
        :type y: numpy.ndarray, shape [n_samples, n_features] or None
        :return: Latent Variable scores (T) for the X matrix and for the Y vector/matrix (U).
        :rtype: tuple with 2 numpy.ndarray, shape [n_samples, n_comps]
        :raise ValueError: If dimensions of input data are mismatched.
        :raise AttributeError: When calling the method before the model is fitted.