interpreTS.core.features package#

Submodules#

interpreTS.core.features.feature_length module#

interpreTS.core.features.feature_length.calculate_length(data)#

Calculate the number of data points in a time series.

Parameters#

datapd.Series or np.ndarray

The time series data for which the length feature is to be calculated.

Returns#

int

The number of data points in the provided time series.

Raises#

TypeError

If the data is not a valid time series type.

ValueError

If the data contains NaN values.

Examples#

>>> import pandas as pd
>>> data = pd.Series([1, 2, 3, 4, 5])
>>> calculate_length(data)
5

interpreTS.core.features.feature_mean module#

interpreTS.core.features.feature_mean.calculate_mean(data)#

Calculate the mean value of a time series.

Parameters#

datapd.Series or np.ndarray

The time series data for which the mean value is to be calculated.

Returns#

float

The mean value of the provided time series.

Raises#

TypeError

If the data is not a valid time series type.

ValueError

If the data contains NaN values.

Examples#

>>> import pandas as pd
>>> data = pd.Series([1, 2, 3, 4, 5])
>>> calculate_mean(data)
3.0

interpreTS.core.features.feature_peak module#

interpreTS.core.features.feature_peak.calculate_peak(data, start=None, end=None)#

Calculate the local maximum of a time series within an optional range.

Parameters#

datapd.Series or np.ndarray

The time series data for which the maximum value is to be calculated.

startint, str, or None, optional

The starting index, timestamp, or position for slicing the data. If None, the series starts from the beginning.

endint, str, or None, optional

The ending index, timestamp, or position for slicing the data. If None, the series ends at the last value.

Returns#

float

The local maximum of the specified range in the provided time series.

Raises#

TypeError

If the data is not a valid time series type.

ValueError

If the data contains NaN values.

Examples#

>>> import pandas as pd
>>> data = pd.Series([1, 2, 5, 4, 7])
>>> calculate_peak(data)
7.0
>>> calculate_peak(data, start=1, end=3)
5.0

interpreTS.core.features.feature_spikeness module#

interpreTS.core.features.feature_spikeness.calculate_spikeness(data)#

Calculate the spikeness (skewness) of a time series.

Parameters#

datapd.Series or np.ndarray

The time series data for which the spikeness is to be calculated.

Returns#

float

The spikeness (skewness) of the provided time series.

Raises#

TypeError

If the data is not a valid time series type.

ValueError

If the data contains NaN values.

Examples#

>>> import pandas as pd
>>> data = pd.Series([1, 2, 3, 4, 5])
>>> calculate_spikeness(data)
0.0

interpreTS.core.features.feature_std_1st_der module#

interpreTS.core.features.feature_std_1st_der.calculate_std_1st_der(data)#

Calculate the standard deviation of the first derivative of a time series.

Parameters#

datapd.Series or np.ndarray

The time series data for which the standard deviation of the first derivative is to be calculated.

Returns#

float

The standard deviation of the first derivative of the provided time series.

Raises#

TypeError

If the data is not a valid time series type.

ValueError

If the data contains NaN values.

Examples#

>>> import pandas as pd
>>> data = pd.Series([1, 2, 3, 4, 5])
>>> calculate_std_1st_derivative(data)
0.0

interpreTS.core.features.feature_trough module#

interpreTS.core.features.feature_trough.calculate_trough(data, start=None, end=None)#

Calculate the local minimum of a time series within an optional range.

Parameters#

datapd.Series or np.ndarray

The time series data for which the minimum value is to be calculated.

startint, str, or None, optional

The starting index, timestamp, or position for slicing the data. If None, the series starts from the beginning.

endint, str, or None, optional

The ending index, timestamp, or position for slicing the data. If None, the series ends at the last value.

Returns#

float

The local minimum of the specified range in the provided time series.

Raises#

TypeError

If the data is not a valid time series type.

ValueError

If the data contains NaN values.

Examples#

>>> import pandas as pd
>>> data = pd.Series([1, 2, 5, 4, 3])
>>> calculate_trough(data)
1.0
>>> calculate_trough(data, start=1, end=3)
2.0

interpreTS.core.features.feature_variance module#

interpreTS.core.features.feature_variance.calculate_variance(data, ddof=1)#

Calculate the variance value of a time series with specified degrees of freedom.

Parameters#

datapd.Series or np.ndarray

The time series data for which the variance is to be calculated.

ddofint, optional

Delta degrees of freedom. The divisor used in calculations is N - ddof, where N is the number of elements. A ddof of 1 provides the sample variance, and a ddof of 0 provides the population variance. Default is 1.

Returns#

float

The variance of the provided time series with specified degrees of freedom.

Raises#

TypeError

If the data is not a valid time series type.

ValueError

If the data contains NaN values.

Examples#

>>> import pandas as pd
>>> data = pd.Series([1, 2, 3, 4, 5])
>>> calculate_variance(data)
2.5
>>> calculate_variance(data, ddof=0)  # Population variance
2.0

interpreTS.core.features.histogram_dominant module#

interpreTS.core.features.histogram_dominant.calculate_dominant(data, bins=10, return_bin_center=False)#

Calculate the dominant value (mode) of a time series histogram.

Parameters#

datapd.Series or np.ndarray

The time series data for which the dominant value is to be calculated.

binsint, optional

The number of bins to use for creating the histogram, by default 10.

Returns#

float

The dominant value (mode) of the histogram.

Raises#

TypeError

If the data is not a valid time series type.

ValueError

If the data contains NaN values.

Examples#

>>> import pandas as pd
>>> data = pd.Series([1, 1, 2, 3, 3, 3, 4, 5])
>>> calculate_dominant(data)
3.0

interpreTS.core.features.seasonality_strength module#

interpreTS.core.features.seasonality_strength.calculate_seasonality_strength(data, period=2, max_lag=12)#

Calculate the strength of the seasonality in a time series based on autocorrelation.

Parameters#

datapd.Series or np.ndarray

The time series data for which the seasonality strength is to be calculated.

periodint, optional

The periodic interval to check for seasonality (default is 2).

max_lagint, optional

The maximum number of lags to consider for autocorrelation (default is 12).

Returns#

float

The seasonality strength, ranging from 0 to 1, where 1 indicates strong seasonality.

Raises#

TypeError

If the data is not a valid time series type.

ValueError

If the data contains NaN values or is too short to calculate seasonality.

Examples#

>>> import pandas as pd
>>> data = pd.Series([1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2], index=pd.date_range("2023-01-01", periods=12, freq="M"))
>>> calculate_seasonality_strength(data, period=3)
0.75

interpreTS.core.features.trend_strength module#

interpreTS.core.features.trend_strength.calculate_trend_strength(data)#

Calculate the strength of the trend in a time series using linear regression.

Parameters#

datapd.Series or np.ndarray

The time series data for which the trend strength is to be calculated.

Returns#

float

The R-squared value representing the strength of the trend (0 to 1).

Raises#

TypeError

If the data is not a valid time series type.

ValueError

If the data contains NaN values.

Examples#

>>> import pandas as pd
>>> data = pd.Series([1, 2, 3, 4, 5])
>>> calculate_trend_strength(data)
1.0

Module contents#