TimeSince
TimeSince
- class TimeSince(start: list[str | datetime | Period | None] | None = None, *, to_numeric: bool | None = True, freq: str | None = None, keep_original_columns: bool | None = False, positive_only: bool | None = False)[source]
Compute element-wise time elapsed between time index and a reference start time.
Creates a column(s) which represents:
t-start, wherestartis a reference time andtis the time index. The type ofstartmust be compatible with the index ofXused in.fit()and.transform().The output can be converted to an integer representing the number of periods elapsed since the start time by setting
to_numeric=True. The period is determined by the frequency of the index. For example, if thefreqof the index is “MS” or “M” then the output is the integer number of months betweentandstart.- Parameters:
- starta list of start times, optional, default=None (use earliest time in index)
a “start time” can be one of the following types:
int: Start time to compute the time elapsed, use when index is integer.
- time-like:
Periodordatetime Start time to compute the time elapsed.
- time-like:
str: String is converted to datetime or period, depending on the index type, to give the start time.
- to_numericstring, optional (default=True)
Return the integer number of periods elapsed since
start; the period is defined by the frequency of the data. Converts datetime types to pd.Period before calculating time differences.- freq‘str’, optional, default=None
Only used when X has a pd.DatetimeIndex without a specified frequency. Specifies the frequency of the index of your data. The string should match a pandas offset alias:
https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases
- keep_original_columnsboolean, optional, default=False
Keep original columns in X passed to
.transform().- positive_onlyboolean, optional, default=False
Clips negative values to zero when
to_numericis True.
- Attributes:
is_fittedWhether
fithas been called.
Examples
>>> from sktime.datasets import load_airline >>> from sktime.transformations.time_since import TimeSince >>> X = load_airline()
Create a single column with time elapsed since start date of time series. The output is in units of integer number of months, same as the index
freq.>>> transformer = TimeSince() >>> Xt = transformer.fit_transform(X)
Create multiple columns with different start times. The output is in units of integer number of months, same as the index
freq.>>> transformer = TimeSince(["2000-01", "2000-02"]) >>> Xt = transformer.fit_transform(X)
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([parameter_set])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.

