Skip to content

PeakTimeFeature

PeakTimeFeature

class PeakTimeFeature(ts_freq=None, peak_hour_start=None, peak_hour_end=None, peak_day_start=None, peak_day_end=None, peak_week_start=None, peak_week_end=None, peak_month_start=None, peak_month_end=None, peak_quarter_start=None, peak_quarter_end=None, peak_year_start=None, peak_year_end=None, working_hour_start=None, working_hour_end=None, keep_original_columns=False, keep_original_peaktime_data_columns=False)[source]

PeakTime feature extraction for use in e.g. tree based models.

PeakTimeFeature uses a datetime index column and generates peak/working features for e.g. peak hours, peak weak, peak month, working hours, etc. It works based on input intervals, start time, end time e.g., peak_hour_start=[6], peak_hour_end=[9]

Parameters:
ts_freqstr, default= None

Restricts selection of items to those with a frequency lower than the frequency of the time series given by ts_freq. E.g., if daily data is provided and ts_freq = (“D”), it does not make sense to derive PeakTimeFeature with higher frequency like hourly features. So, the outpul must exclude is_peak_hour and will be is_peak_day, is_peak_week, is_peak_month, is_peak_quarter, is_peak_year. Only supports the following frequencies: {“Y”: year, “Q”: quarter, “M”: month, “W”: week, “D”: day, “H”: hour}

peak_hour_startlist, default= None

start interval of peak hour(s) in a list where the first argument determines the first start hour, the second one determines the second start hour and so on. [peak_hour_start1, peak_hour_start2, peak_hour_start3, …]

peak_hour_endlist, default= None

end interval of peak hour(s) in a list where the first argument determines the first end hour, the second one determines the second end hour and so on. [peak_hour_end1, peak_hour_end2, peak_hour_end3, …]

peak_day_startlist, default= None

start interval of peak day(s) in a list where the first argument determines the first start day, the second one determines the second start day and so on. [peak_day_start1, peak_day_start2, peak_day_start3, …]

peak_day_endlist, default= None

end interval of peak day(s) in a list where the first argument determines the first end day, the second one determines the second end day and so on. [peak_day_end1, peak_day_end2, peak_day_end3, …]

peak_week_startlist, default= None

start interval of peak week(s) in a list where the first argument determines the first start week, the second one determines the second start week and so on. [peak_week_start1, peak_week_start2, peak_week_start3, …]

peak_week_endlist, default= None

end interval of peak week(s) in a list where the first argument determines the first end week, the second one determines the second end week and so on. [peak_week_end1, peak_week_end2, peak_week_end3, …]

peak_month_startlist, default= None

start interval of peak month(s) in a list where the first argument determines the first start month, the second one determines the second start month and so on. [peak_month_start1, peak_month_start2, peak_month_start3, …]

peak_month_endlist, default= None

end interval of peak month(s) in a list where the first argument determines the first end month, the second one determines the second end month and so on. [peak_month_end1, peak_month_end2, peak_month_end3, …]

peak_quarter_startlist, default= None

start interval of peak quarter(s) in a list where the first argument determines first start quarter, the second one determines the second start quarter and so on. [peak_quarter_start1, peak_quarter_start2, peak_quarter_start3, …]

peak_quarter_endlist, default= None

end interval of peak quarter(s) in a list where the first argument determines first end quarter, the second one determines the second end quarter and so on. [peak_quarter_end1, peak_quarter_end2, peak_quarter_end3, …]

peak_year_startlist, default= None

start interval of peak year(s) in a list where the first argument determines first start year, the second one determines the second start year and so on. [peak_year_start1, peak_year_start2, peak_year_start3, …]

peak_year_endlist, default= None

end interval of peak year(s) in a list where the first argument determines first end year, the second one determines the second end year and so on. [peak_year_end1, peak_year_end2, peak_year_end3, …]

working_hour_startlist, default= None

start interval of working hour(s) in a list where the first argument determines first start working hour, the second one determines the second start working hour and so on. e.g., [working_hour_start1, working_hour_start2, working_hour_start3, …]

working_hour_endlist, default= None

end interval of working hour(s) in a list where the first argument determines first end working hour, the second one determines the second end working hour and so on. [working_hour_end1, working_hour_end2, working_hour_end3, …]

keep_original_columnsboolean, optional, default=False

If True, keep original columns in main dataframe (X) passed to .transform().

keep_original_peaktime_data_columns: boolean, optional, default=False

If True, keep original peaktime_data dataframe columns including all separate peak/working columns, e.g., peak_hour_1, peak_hour_2, peak_week_1, peak_week_2, …

Attributes:
is_fitted

Whether fit has been called.

Notes

  • Descriptions and offsets for calendar features are as follows:

hour:

The hour of the day with 00:00:00 = 0, 23:00:00 = 23.

day_of_week:

The day of the week with Monday=0, Sunday=6.

week_of_year:

The week of the year (ISO calendar), start = 1, end = 52 or 53

month_of_year:

The month as January=1, December=12.

quarter:

The quarter of the year as: January, February, March = 1 April, May, June, = 2 July, August, September = 3 October, November, December = 4

year:

The year of the datetime.

  • Descriptions for different intervals:

1- Example for one peak interval: peak_hour_start=[6], peak_hour_end=[9] means we have just one peak hour interval where peak starts at 6am and peak ends at 9am.

2- Example for two peak intervals: peak_hour_start=[6, 16], peak_hour_end=[9, 20] means we have two peak hour intervals where the first peak starts at 6 am and ends at 9 am. The second peak starts at 16 am and ends at 20. we can have more than two intervals.

3- Example for one working interval: working_hour_start=[8], working_hour_end=[16] means we have just one working hour interval where work starts at 8 am and work ends at 16.

4- Example for two working intervals: working_hour_start=[8, 15], working_hour_end=[12, 19] means we have two working hour intervals where the first starts at 8 am and ends at 15. The second starts at 15 am and ends at 19. we can have more than two intervals.

Examples

>>> from sktime.transformations.peak import PeakTimeFeature
>>> from sktime.datasets import
>>> y = load_solar()
>>> y = y.tz_localize(None)
>>> y = y.asfreq("H")

Example 1: one interval for peak hour and working hour. (based on one start/end interval)

Returns columns is_peak_hour, is_working_hour

>>> transformer = PeakTimeFeature(ts_freq="H",
... peak_hour_start=[6], peak_hour_end=[9],
... working_hour_start=[8], working_hour_end=[16]
... )
>>> y_hat_peak = transformer.fit_transform(y)

Example 2: two intervals for peak hour and working hour. (based on two start/end intervals)

Returns columns is_peak_hour, is_working_hour

>>> transformer = PeakTimeFeature(ts_freq="H",
... peak_hour_start=[6, 16], peak_hour_end=[9, 20],
... working_hour_start=[8, 15], working_hour_end=[12, 19]
... )
>>> y_hat_peak = transformer.fit_transform(y)

Example 3: We may have peak for different seasonality Here is an example for peak hour, peak day, peak week, peak month for two intervals (based on two start/end intervals)

Returns columns is_peak_hour, is_peak_day, is_peak_week, is_peak_month

>>> transformer = PeakTimeFeature(ts_freq="H",
... peak_hour_start=[6, 16], peak_hour_end=[9, 20],
... peak_day_start=[1, 2], peak_day_end=[2, 3],
... peak_week_start=[35, 45], peak_week_end=[40, 52],
... peak_month_start=[1, 7], peak_month_end=[6, 12]
... )
>>> y_hat_peak = transformer.fit_transform(y)

Methods

check_is_fitted([method_name])

Check if the estimator has been fitted.

clone()

Obtain a clone of the object with same hyper-parameters and config.

clone_tags(estimator[, tag_names])

Clone tags from another object as dynamic override.

create_test_instance([parameter_set])

Construct an instance of the class, using first test parameter set.

create_test_instances_and_names([parameter_set])

Create list of all test instances and a list of names for them.

fit(X[, y])

Fit transformer to X, optionally to y.

fit_transform(X[, y])

Fit to data, then transform it.

get_class_tag(tag_name[, tag_value_default])

Get class tag value from class, with tag level inheritance from parents.

get_class_tags()

Get class tags from class, with tag level inheritance from parent classes.

get_config()

Get config flags for self.

get_fitted_params([deep])

Get fitted parameters.

get_param_defaults()

Get object's parameter defaults.

get_param_names([sort])

Get object's parameter names.

get_params([deep])

Get a dict of parameters values for this object.

get_tag(tag_name[, tag_value_default, ...])

Get tag value from instance, with tag level inheritance and overrides.

get_tags()

Get tags from instance, with tag level inheritance and overrides.

get_test_params()

Return testing parameter settings for the estimator.

inverse_transform(X[, y])

Inverse transform X and return an inverse transformed version.

is_composite()

Check if the object is composed of other BaseObjects.

load_from_path(serial)

Load object from file location.

load_from_serial(serial)

Load object from serialized memory container.

reset()

Reset the object to a clean post-init state.

save([path, serialization_format])

Save serialized self to bytes-like object or to (.zip) file.

set_config(**config_dict)

Set config flags to given values.

set_params(**params)

Set the parameters of this object.

set_random_state([random_state, deep, ...])

Set random_state pseudo-random seed parameters for self.

set_tags(**tag_dict)

Set instance level tag overrides to given values.

transform(X[, y])

Transform X and return a transformed version.

update(X[, y, update_params])

Update transformer with X, optionally y.