featuretools
featuretools copied to clipboard
Add RollingOutlierCount primitive
Featuretools could include a RollingOutlierCount
transform primitive that, like the other rolling primitives, takes in window_length
and gap
parameters and allows users to create features that indicate a level of volatility in their data over rolling windows.
class RollingOutlierCount(TransformPrimitive):
name = "rolling_outlier_count"
input_types = [ColumnSchema(logical_type=Datetime, semantic_tags={'time_index'}), ColumnSchema(semantic_tags={'numeric'})]
return_type = ColumnSchema(logical_type=Double, semantic_tags={'numeric'})
def __init__(self, window_length=3, gap=0, min_periods=0):
self.window_length = window_length
self.gap = gap
self.min_periods = min_periods
def get_function(self):
def rolling_outlier_count(datetime, numeric):
x = pd.Series(numeric.values, index=datetime.values)
rolled_series = _roll_series_with_gap(x,
self.window_length,
gap=self.gap,
min_periods=self.min_periods)
# get_outliers would be defined elsewhere, but it could use woodwork's box_plot_dict
return rolled_series.apply(get_outliers).values
return rolling_outlier_count