@@ -721,7 +721,7 @@ def fit(
721721 }
722722 # Validate data
723723 X = sklearn .utils .validation .check_array (X , ** self ._check_array_params )
724- # Set numbre of input features (including episode feature)
724+ # Set number of input features (including episode feature)
725725 self .n_features_in_ = X .shape [1 ]
726726 # Extract episode feature
727727 if self .episode_feature_ :
@@ -751,12 +751,11 @@ def transform(self, X: np.ndarray) -> np.ndarray:
751751 X ,
752752 ** self ._check_array_params ,
753753 )
754- # Check input shape
754+ # Check number of features
755755 if X .shape [1 ] != self .n_features_in_ :
756- raise ValueError (f'{ self .__class__ .__name__ } `fit()` called '
757- f'with { self .n_features_in_ } features, but '
758- f'`transform()` called with { X .shape [1 ]} '
759- 'features.' )
756+ raise ValueError (
757+ f"X has { X .shape [1 ]} features, but { self .__class__ .__name__ } "
758+ f"is expecting { self .n_features_in_ } features as input." )
760759 return self ._apply_transform_or_inverse (X , 'transform' )
761760
762761 def inverse_transform (self , X : np .ndarray ) -> np .ndarray :
@@ -996,12 +995,11 @@ def transform(self, X: np.ndarray) -> np.ndarray:
996995 X ,
997996 ** self ._check_array_params ,
998997 )
999- # Check input shape
998+ # Check number of features
1000999 if X .shape [1 ] != self .n_features_in_ :
1001- raise ValueError (f'{ self .__class__ .__name__ } `fit()` called '
1002- f'with { self .n_features_in_ } features, but '
1003- f'`transform()` called with { X .shape [1 ]} '
1004- 'features.' )
1000+ raise ValueError (
1001+ f"X has { X .shape [1 ]} features, but { self .__class__ .__name__ } "
1002+ f"is expecting { self .n_features_in_ } features as input." )
10051003 return self ._apply_transform_or_inverse (X , 'transform' )
10061004
10071005 def inverse_transform (self , X : np .ndarray ) -> np .ndarray :
@@ -1014,12 +1012,11 @@ def inverse_transform(self, X: np.ndarray) -> np.ndarray:
10141012 X ,
10151013 ** self ._check_array_params ,
10161014 )
1017- # Check input shape
1015+ # Check number of features
10181016 if X .shape [1 ] != self .n_features_out_ :
1019- raise ValueError (f'{ self .__class__ .__name__ } `fit()` output '
1020- f'{ self .n_features_out_ } features, but '
1021- '`inverse_transform()` called with '
1022- f'{ X .shape [1 ]} features.' )
1017+ raise ValueError (
1018+ f"X has { X .shape [1 ]} features, but { self .__class__ .__name__ } "
1019+ f"is expecting { self .n_features_out_ } features as input." )
10231020 return self ._apply_transform_or_inverse (X , 'inverse_transform' )
10241021
10251022 def _apply_transform_or_inverse (self , X : np .ndarray ,
@@ -1270,6 +1267,11 @@ def predict(self, X: np.ndarray) -> np.ndarray:
12701267 self ._validate_feature_names (X )
12711268 # Validate array
12721269 X = sklearn .utils .validation .check_array (X , ** self ._check_array_params )
1270+ # Check number of features
1271+ if X .shape [1 ] != self .n_features_in_ :
1272+ raise ValueError (
1273+ f"X has { X .shape [1 ]} features, but { self .__class__ .__name__ } "
1274+ f"is expecting { self .n_features_in_ } features as input." )
12731275 # Split episodes
12741276 episodes = split_episodes (X , episode_feature = self .episode_feature_ )
12751277 # Predict for each episode
@@ -1623,8 +1625,13 @@ def _validate_feature_names(self, X: np.ndarray) -> None:
16231625 if not np .all (_extract_feature_names (X ) == self .feature_names_in_ ):
16241626 raise ValueError ('Input features do not match fit features.' )
16251627
1626- # Extra estimator tags
1627- # https://scikit-learn.org/stable/developers/develop.html#estimator-tags
1628+ def __sklearn_tags__ (self ):
1629+ tags = super ().__sklearn_tags__ ()
1630+ tags .target_tags .required = False
1631+ tags .target_tags .single_output = False
1632+ tags .target_tags .multi_output = True
1633+ return tags
1634+
16281635 def _more_tags (self ):
16291636 return {
16301637 'multioutput' : True ,
@@ -1812,12 +1819,11 @@ def transform(self, X: np.ndarray) -> np.ndarray:
18121819 X ,
18131820 ** self ._check_array_params ,
18141821 )
1815- # Check input shape
1822+ # Check number of features
18161823 if X .shape [1 ] != self .n_features_in_ :
1817- raise ValueError (f'{ self .__class__ .__name__ } `fit()` called '
1818- f'with { self .n_features_in_ } features, but '
1819- f'`transform()` called with { X .shape [1 ]} '
1820- 'features.' )
1824+ raise ValueError (
1825+ f"X has { X .shape [1 ]} features, but { self .__class__ .__name__ } "
1826+ f"is expecting { self .n_features_in_ } features as input." )
18211827 # Split episodes
18221828 episodes = split_episodes (X , episode_feature = self .episode_feature_ )
18231829 episodes_state = []
@@ -1873,12 +1879,11 @@ def inverse_transform(self, X: np.ndarray) -> np.ndarray:
18731879 sklearn .utils .validation .check_is_fitted (self )
18741880 X = sklearn .utils .validation .check_array (
18751881 X , ** self ._check_array_params )
1876- # Check input shape
1882+ # Check number of features
18771883 if X .shape [1 ] != self .n_features_out_ :
1878- raise ValueError (f'{ self .__class__ .__name__ } `fit()` output '
1879- f'{ self .n_features_out_ } features, but '
1880- '`inverse_transform()` called with '
1881- f'{ X .shape [1 ]} features.' )
1884+ raise ValueError (
1885+ f"X has { X .shape [1 ]} features, but { self .__class__ .__name__ } "
1886+ f"is expecting { self .n_features_out_ } features as input." )
18821887 # Split episodes
18831888 episodes = split_episodes (X , episode_feature = self .episode_feature_ )
18841889 episodes_state = []
@@ -2278,12 +2283,11 @@ def transform(self, X: np.ndarray) -> np.ndarray:
22782283 X ,
22792284 ** self ._check_array_params ,
22802285 )
2281- # Check input shape
2286+ # Check number of features
22822287 if X .shape [1 ] != self .n_features_in_ :
2283- raise ValueError (f'{ self .__class__ .__name__ } `fit()` called '
2284- f'with { self .n_features_in_ } features, but '
2285- f'`transform()` called with { X .shape [1 ]} '
2286- 'features.' )
2288+ raise ValueError (
2289+ f"X has { X .shape [1 ]} features, but { self .__class__ .__name__ } "
2290+ f"is expecting { self .n_features_in_ } features as input." )
22872291 # Apply lifting functions
22882292 X_out = X
22892293 for _ , lf in self .lifting_functions_ :
@@ -2309,12 +2313,11 @@ def inverse_transform(self, X: np.ndarray) -> np.ndarray:
23092313 X ,
23102314 ** self ._check_array_params ,
23112315 )
2312- # Check input shape
2316+ # Check number of features
23132317 if X .shape [1 ] != self .n_features_out_ :
2314- raise ValueError (f'{ self .__class__ .__name__ } `fit()` output '
2315- f'{ self .n_features_out_ } features, but '
2316- '`inverse_transform()` called with '
2317- f'{ X .shape [1 ]} features.' )
2318+ raise ValueError (
2319+ f"X has { X .shape [1 ]} features, but { self .__class__ .__name__ } "
2320+ f"is expecting { self .n_features_out_ } features as input." )
23182321 # Apply inverse lifting functions in reverse order
23192322 X_out = X
23202323 for _ , lf in self .lifting_functions_ [::- 1 ]:
@@ -2360,6 +2363,11 @@ def predict(self, X: np.ndarray) -> np.ndarray:
23602363 X ,
23612364 ** self ._check_array_params ,
23622365 )
2366+ # Check number of features
2367+ if X .shape [1 ] != self .n_features_in_ :
2368+ raise ValueError (
2369+ f"X has { X .shape [1 ]} features, but { self .__class__ .__name__ } "
2370+ f"is expecting { self .n_features_in_ } features as input." )
23632371 # Lift data matrix
23642372 X_trans = self .transform (X )
23652373 # Predict in lifted space
@@ -2405,6 +2413,11 @@ def score(self, X: np.ndarray, y: Optional[np.ndarray] = None) -> float:
24052413 self ._validate_feature_names (X )
24062414 # Validate input array
24072415 X = sklearn .utils .validation .check_array (X , ** self ._check_array_params )
2416+ # Check number of features
2417+ if X .shape [1 ] != self .n_features_in_ :
2418+ raise ValueError (
2419+ f"X has { X .shape [1 ]} features, but { self .__class__ .__name__ } "
2420+ f"is expecting { self .n_features_in_ } features as input." )
24082421 scorer = KoopmanPipeline .make_scorer ()
24092422 score = scorer (self , X , None )
24102423 return score
0 commit comments