1010from sklearn .decomposition ._pca import _infer_dimension
1111from sklearn .linear_model import LinearRegression , Ridge , RidgeCV
1212from sklearn .linear_model ._base import LinearModel
13- from sklearn .utils import check_array , check_random_state
13+ from sklearn .utils import check_random_state
1414from sklearn .utils ._arpack import _init_arpack_v0
1515from sklearn .utils .extmath import randomized_svd , stable_cumsum , svd_flip
16- from sklearn .utils .validation import check_is_fitted , check_X_y
16+ from sklearn .utils .validation import check_is_fitted , validate_data
1717
1818from ..utils import check_lr_fit , pcovr_covariance , pcovr_kernel
1919
@@ -221,7 +221,8 @@ def fit(self, X, Y, W=None):
221221 Regression weights, optional when regressor=`precomputed`. If not
222222 passed, it is assumed that `W = np.linalg.lstsq(X, Y, self.tol)[0]`
223223 """
224- X , Y = check_X_y (X , Y , y_numeric = True , multi_output = True )
224+
225+ X , Y = validate_data (self , X , Y , y_numeric = True , multi_output = True )
225226
226227 # saved for inverse transformations from the latent space,
227228 # should be zero in the case that the features have been properly centered
@@ -582,10 +583,10 @@ def predict(self, X=None, T=None):
582583 raise ValueError ("Either X or T must be supplied." )
583584
584585 if X is not None :
585- X = check_array ( X )
586+ X = validate_data ( self , X , reset = False )
586587 return X @ self .pxy_
587588 else :
588- T = check_array ( T )
589+ T = validate_data ( self , T , reset = False )
589590 return T @ self .pty_
590591
591592 def transform (self , X = None ):
@@ -604,7 +605,7 @@ def transform(self, X=None):
604605
605606 return super ().transform (X )
606607
607- def score (self , X , Y , T = None ):
608+ def score (self , X , y , T = None ):
608609 r"""Return the (negative) total reconstruction error for X and Y,
609610 defined as:
610611
@@ -635,13 +636,16 @@ def score(self, X, Y, T=None):
635636 Negative sum of the loss in reconstructing X from the latent-space
636637 projection T and the loss in predicting Y from the latent-space projection T
637638 """
639+
640+ X , y = validate_data (self , X , y , reset = False )
641+
638642 if T is None :
639643 T = self .transform (X )
640644
641- x = self .inverse_transform (T )
642- y = self .predict (T = T )
645+ Xrec = self .inverse_transform (T )
646+ ypred = self .predict (T = T )
643647
644648 return - (
645- np .linalg .norm (X - x ) ** 2.0 / np .linalg .norm (X ) ** 2.0
646- + np .linalg .norm (Y - y ) ** 2.0 / np .linalg .norm (Y ) ** 2.0
649+ np .linalg .norm (X - Xrec ) ** 2.0 / np .linalg .norm (X ) ** 2.0
650+ + np .linalg .norm (y - ypred ) ** 2.0 / np .linalg .norm (y ) ** 2.0
647651 )
0 commit comments