Skip to main content

No project description provided

Project description

Period-Detection

If you use the presented period detection method or the provided Python scripts inspired you for further extensions or variations of this framework, we’ll be happy if you cite our paper “On a method for detecting periods and repeating patterns in time series data with autocorrelation and function approximation” (https://doi.org/10.1016/j.patcog.2023.109355) in course of which the Python implementations of this git repository have been worked out.

Installation

pip install period-detection

Usage

from period_detection import find_period

find_period(path="time_series_data.csv") # function call

Parameters

  • path (String, required): Path to the timeseries data
  • tol_norm_diff (float, default=0.001): The tolerance for the norm difference between the the data and the fitted model, see res_criteria = 1.5.
  • number_steps (int, default=1000): Number of steps by which the range 0 to 1 of the threshold for zero (sigma) is divided.
  • minimum_number_of_relevant_shifts (int, default=2): The minimum number of shifts required for calculation of the period.
  • minimum_number_of_datapoints_for_correlation_test (int, default=300): The minimum number of datapoints required for calculation.
  • minimum_ratio_of_datapoints_for_shift_autocorrelation (float, default=0.3): The minimum ratio of datapoints for which we calculate the autocorrelation of a shift.
  • consider_only_significant_correlation (bool, default=True): A flag declaring the usage only of correlations matching significance.
  • level_of_significance_for_pearson (float, default=0.01): The minimum significance level for the correlation criterion.
  • output_flag (bool, default=True): Output flag setting plotting to on/off.
  • plot_tolerances (bool, default=True): Output flag allowing for tolerances to be plotted.
  • reference_time (pd.Timestamp, default=pd.Timestamp('2017-01-01T12')): The reference point for phase calculation.

Output

These are the possible outputs you get when the output_flag is set during execution.

In case a period is found

  1. A comparison of the original timeseries and the one predicted by the model.
  2. A plot of the norm difference between unshifted and shifted autocorrelation function, optionally with tolerances (horizontal lines).
  3. A plot of the autocorrelation function of the data linking the autocorrelation function to the correlation coefficient r and the significance p.
  4. A plot of the difference between the original timeseries and the model. In case the model fits well this is only noise.
  5. A plot of the autocorrelation function of the original data minus the model. A low autocorrelation function value here indicates a well fit model.

In case no period was found

  1. A plot of the timeseries data
  2. A plot of the norm difference between unshifted and shifted autocorrelation function.
  3. A plot of the autocorrelation function of the data linking the autocorrelation function to the correlation coefficient r and the significance p.

Returns

The function find_period returns a namedtuple Results(period, model, criteria).

In case a period is found

  • res_period (float): The period duration itself in minutes.
  • res_model (RandomForestRegressor object): The best performing model trained to fit the timeseries.
  • res_criteria (float): A float acting as performance criterium for the model. Between 0 and 1, set to 1.5 in case of a near perfect fit for the model.

In case no period is found

  • res_period (float): Set to -1 as no period exists.
  • res_model (RandomForestRegressor object): Set to None as no model exists.
  • res_criteria (float): Set to 0 as there is no model that fits the timeseries.

In case of an error

If an error occurs during execution the error message is printed and further code will still be executed.

  • res_period (float): Set to -2 in order to indicate an error.
  • res_model (RandomForestRegressor object): Set to None as no model exists.
  • res_criteria (float): Set to -2 in order to indicate an error.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

period-detection-1.1.2.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

period_detection-1.1.2-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file period-detection-1.1.2.tar.gz.

File metadata

  • Download URL: period-detection-1.1.2.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for period-detection-1.1.2.tar.gz
Algorithm Hash digest
SHA256 38e715b6c92b6f88eb9dd4b35c5836e1de7a0bcb39512440f399466a2bb21b83
MD5 40f6dcb684414c43e67ef9bed1464c3e
BLAKE2b-256 2d286d902d71f74cf91066566f3b361e81096747ddcbff669469aa470fbf0073

See more details on using hashes here.

File details

Details for the file period_detection-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for period_detection-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 69ef1036b7d2722deb735df0d0e121bbe63446f5a3f74de3c6d310a1859f1cc6
MD5 0c9488e7d9957d46fd26bd956663fb31
BLAKE2b-256 666217ce2337324d0eb8a549e2d207e29c177985ea7de50ed45454bc573cf463

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page