DateTimeFeatures
DateTimeFeatures
- class DateTimeFeatures(ts_freq=None, feature_scope='minimal', manual_selection=None, keep_original_columns=False)[source]
DateTime feature extraction, e.g., for use as exogenous data in forecasting.
DateTimeFeatures uses a date index column and generates date features identifying e.g. year, week of the year, day of the week.
- Parameters:
- ts_freqstr, optional (default=”day”)
Frequency of the time series. Restricts selection of items to those with a frequency lower than the frequency of the time series given by ts_freq. E.g. if monthly data is provided and ts_freq = (“M”), it does not make sense to derive dummies with higher frequency like weekly dummies. Has to be provided by the user due to the abundance of different frequencies supported by Pandas (e.g. every pandas allows freq of every 4 days). Interaction with other arguments: Used to narrow down feature selection for feature_scope, since only features with a frequency lower than ts_freq are considered. Will be ignored for the calculation of manually specified features, but when provided will raise a warning if manual features have a frequency higher than ts_freq. Only supports the following frequencies:
Y - year
Q - quarter
M - month
W - week
D - day
H - hour
T - minute
S - second
L - millisecond
- feature_scope: str, optional (default=”minimal”)
Specify how many calendar features you want to be returned. E.g., rarely used features like week of quarter will only be returned with feature_scope = “comprehensive”.
“minimal”
“efficient”
“comprehensive”
- manual_selection: str, optional (default=None)
Manual selection of dummys. Notation is child of parent for precise notation. Will ignore specified feature_scope, but will still check with warning against a specified ts_freq. All columns returned are integer based. Dates are presented in DD-MM-YYYY format below. Supported values:
None
- quarter_of_year
1-based index 1-(Jan to Mar), 2-(Apr to Jun), 3-(Jul to Sep), 4-(Oct to Dec)
- month_of_year
1-based offset to January 1-January,2-February,…,12-December
- week_of_year
1-based offset to the first week of an ISO year
- day_of_year
1-based offset to first of January 1 is 01-01-YYYY, 2 is 02-01-YYYY and so on.
- month_of_quarter
1-based index to first month of each quarter(Jan,Apr,Jul,Oct) For the first quarter: 1-January, 2-February, 3-March
- week_of_quarter
1-based offset to first week of the quarter. The first/last week of the quarter may or may not include 7 days. All other weeks have 7 days. A week is taken to start on Monday. If the month begins on a Monday, then the first seven days upto the next Monday is week 1. Otherwise, week 1 is from the 1st of that month upto the first Monday. Example:
If 01-01-YYYY is a Monday, Week 1 : Mon,Tue,Wed,Thu,Fri,Sat,Sun(07-01-YYYY) Week 2 : Mon(08-01-YYYY),Tue,…,Sun If 01-01-YYYY is a Thursday, Week 1 : Thu,Fri,Sat,Sun(04-01-YYYY) Week 2 : Mon(05-01-YYYY),Tue,…,Sun
- day_of_quarter
1-based index
- week_of_month
1-based index 1 indicates the first week of the month. First week includes the first 7 days of the month(01-MM-YYYY to 07-MM-YYYY) 2 indicates the second week of the month. Second week includes the next 7 days(08-MM-YYYY to 14-MM-YYYY) and so on.
- day_of_month
1-based offset to first day of each month 1 is 01-MM-YYYY, 2 is 02-MM-YYYY and so on.
- day_of_week
0-based offset to Monday 0-Monday,1-Tuesday,…,6-Sunday
- hour_of_week
0-based offset to Monday(00:00:00+00:00)
- hour_of_day
0-based offset to 00:00:00+00:00
- minute_of_hour
0-based offset to 00:00:00
- second_of_minute
0-based offset to 00:00:00
- millisecond_of_second
0-based offset to 00:00:00.0000
- is_weekend
1 indicates weekend, 0 indicates it is not a weekend
year (special case with no lower frequency).
- keep_original_columnsboolean, optional, default=False
Keep original columns in X passed to
.transform().
- Attributes:
is_fittedWhether
fithas been called.
Examples
>>> from sktime.transformations.date import DateTimeFeatures >>> from sktime.datasets import load_airline >>> y = load_airline()
Returns columns
y,year,month_of_year>>> transformer = DateTimeFeatures(ts_freq="M") >>> y_hat = transformer.fit_transform(y)
Returns columns
y,month_of_year>>> transformer = DateTimeFeatures(ts_freq="M", manual_selection=["month_of_year"]) >>> y_hat = transformer.fit_transform(y)
Returns columns ‘y’, ‘year’, ‘quarter_of_year’, ‘month_of_year’, ‘month_of_quarter’
>>> transformer = DateTimeFeatures(ts_freq="M", feature_scope="comprehensive") >>> y_hat = transformer.fit_transform(y)
Returns columns ‘y’, ‘year’, ‘quarter_of_year’, ‘month_of_year’
>>> transformer = DateTimeFeatures(ts_freq="M", feature_scope="efficient") >>> y_hat = transformer.fit_transform(y)
Returns columns ‘y’, ‘year’, ‘month_of_year’
>>> transformer = DateTimeFeatures(ts_freq="M", feature_scope="minimal") >>> y_hat = 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.

