in src/sagemaker_sklearn_extension/feature_extraction/sequences.py [0:0]
def _filter_features(self, tsfresh_features, mode="transform", transform_thresholds=None):
if self.expansion_threshold < self.min_settings_card:
raise ValueError(
f"Provided filter threshold(s) (= {self.expansion_threshold}) can not be smaller than "
f"number of features generated by minimal settings (= {self.min_settings_card})"
)
filter_order = np.arange(self.min_settings_card, tsfresh_features.shape[1])
random_state = np.random.get_state()
np.random.seed(self.feature_sampling_seed)
np.random.shuffle(filter_order)
np.random.set_state(random_state)
survivors = list(range(self.min_settings_card)) + list(
filter_order[: self.expansion_threshold - self.min_settings_card]
)
tsfresh_features = tsfresh_features.iloc[:, survivors]
if mode == "transform":
if len(transform_thresholds) != tsfresh_features.shape[0]:
raise ValueError(
f"In 'transform' mode transform_thresholds should have number of entries "
f"(= {len(transform_thresholds)}) that corresponds to the number of records "
f"in tsfresh_features (= {tsfresh_features.shape[0]})."
)
for thrsh_i, thrsh in enumerate(transform_thresholds):
tsfresh_features.iloc[thrsh_i, thrsh:] = 0
return tsfresh_features