@@ -721,7 +721,7 @@ def fit(
721
721
}
722
722
# Validate data
723
723
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)
725
725
self .n_features_in_ = X .shape [1 ]
726
726
# Extract episode feature
727
727
if self .episode_feature_ :
@@ -751,12 +751,11 @@ def transform(self, X: np.ndarray) -> np.ndarray:
751
751
X ,
752
752
** self ._check_array_params ,
753
753
)
754
- # Check input shape
754
+ # Check number of features
755
755
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." )
760
759
return self ._apply_transform_or_inverse (X , 'transform' )
761
760
762
761
def inverse_transform (self , X : np .ndarray ) -> np .ndarray :
@@ -996,12 +995,11 @@ def transform(self, X: np.ndarray) -> np.ndarray:
996
995
X ,
997
996
** self ._check_array_params ,
998
997
)
999
- # Check input shape
998
+ # Check number of features
1000
999
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." )
1005
1003
return self ._apply_transform_or_inverse (X , 'transform' )
1006
1004
1007
1005
def inverse_transform (self , X : np .ndarray ) -> np .ndarray :
@@ -1014,12 +1012,11 @@ def inverse_transform(self, X: np.ndarray) -> np.ndarray:
1014
1012
X ,
1015
1013
** self ._check_array_params ,
1016
1014
)
1017
- # Check input shape
1015
+ # Check number of features
1018
1016
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." )
1023
1020
return self ._apply_transform_or_inverse (X , 'inverse_transform' )
1024
1021
1025
1022
def _apply_transform_or_inverse (self , X : np .ndarray ,
@@ -1270,6 +1267,11 @@ def predict(self, X: np.ndarray) -> np.ndarray:
1270
1267
self ._validate_feature_names (X )
1271
1268
# Validate array
1272
1269
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." )
1273
1275
# Split episodes
1274
1276
episodes = split_episodes (X , episode_feature = self .episode_feature_ )
1275
1277
# Predict for each episode
@@ -1623,8 +1625,13 @@ def _validate_feature_names(self, X: np.ndarray) -> None:
1623
1625
if not np .all (_extract_feature_names (X ) == self .feature_names_in_ ):
1624
1626
raise ValueError ('Input features do not match fit features.' )
1625
1627
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
+
1628
1635
def _more_tags (self ):
1629
1636
return {
1630
1637
'multioutput' : True ,
@@ -1812,12 +1819,11 @@ def transform(self, X: np.ndarray) -> np.ndarray:
1812
1819
X ,
1813
1820
** self ._check_array_params ,
1814
1821
)
1815
- # Check input shape
1822
+ # Check number of features
1816
1823
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." )
1821
1827
# Split episodes
1822
1828
episodes = split_episodes (X , episode_feature = self .episode_feature_ )
1823
1829
episodes_state = []
@@ -1873,12 +1879,11 @@ def inverse_transform(self, X: np.ndarray) -> np.ndarray:
1873
1879
sklearn .utils .validation .check_is_fitted (self )
1874
1880
X = sklearn .utils .validation .check_array (
1875
1881
X , ** self ._check_array_params )
1876
- # Check input shape
1882
+ # Check number of features
1877
1883
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." )
1882
1887
# Split episodes
1883
1888
episodes = split_episodes (X , episode_feature = self .episode_feature_ )
1884
1889
episodes_state = []
@@ -2278,12 +2283,11 @@ def transform(self, X: np.ndarray) -> np.ndarray:
2278
2283
X ,
2279
2284
** self ._check_array_params ,
2280
2285
)
2281
- # Check input shape
2286
+ # Check number of features
2282
2287
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." )
2287
2291
# Apply lifting functions
2288
2292
X_out = X
2289
2293
for _ , lf in self .lifting_functions_ :
@@ -2309,12 +2313,11 @@ def inverse_transform(self, X: np.ndarray) -> np.ndarray:
2309
2313
X ,
2310
2314
** self ._check_array_params ,
2311
2315
)
2312
- # Check input shape
2316
+ # Check number of features
2313
2317
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." )
2318
2321
# Apply inverse lifting functions in reverse order
2319
2322
X_out = X
2320
2323
for _ , lf in self .lifting_functions_ [::- 1 ]:
@@ -2360,6 +2363,11 @@ def predict(self, X: np.ndarray) -> np.ndarray:
2360
2363
X ,
2361
2364
** self ._check_array_params ,
2362
2365
)
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." )
2363
2371
# Lift data matrix
2364
2372
X_trans = self .transform (X )
2365
2373
# Predict in lifted space
@@ -2405,6 +2413,11 @@ def score(self, X: np.ndarray, y: Optional[np.ndarray] = None) -> float:
2405
2413
self ._validate_feature_names (X )
2406
2414
# Validate input array
2407
2415
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." )
2408
2421
scorer = KoopmanPipeline .make_scorer ()
2409
2422
score = scorer (self , X , None )
2410
2423
return score
0 commit comments