TPCS is a metric to assess how well time-dependent patterns within a time series signal remain connected over time, with an emphasis on recency.
Project description
Time Pattern Cohesion Score
Introduction
https://pypi.org/project/tpcs/0.0.4/
TPCS is a metric to assess how well time-dependent patterns within a time series signal remain connected over time, with an emphasis on recency.
We calculate TPCS using 4 main features :
Consistency : shows if data collection is consistent with respect to start and end time of data crawling , (from 2020-09 to current time)
Intra Consistency : shows if data collection was consistent with respect to signal’s own start and end time.
Contiguity : shows how contiguous data is. 5 is fully contiguous which means all existed values are sequential
Recent Contiguity : shows how contiguous recent data is.
Table of Contents
Installation & Import
pip install tpcs
import pandas as pd
from time_pattern_cohesion_score import TPCS
END_OF_TIME= pd.to_datetime("2021-05-01")
MAX_LEN_MONTHS=13
list_of_timestamps= ["2020-05-01","2020-06-01","2020-07-01","2020-08-01","2020-09-01","2020-10-01","2020-11-01","2020-12-01","2021-01-01", "2021-03-01","2021-04-01","2021-05-01" ]
#notice that "2021-02-01" is missing
list_of_timestamps= [pd.to_datetime(e) for e in list_of_timestamps]
tpcs=TPCS(list_of_timestamps,MAX_LEN_MONTHS, END_OF_TIME )
print(tpcs.calculate_TPCS())
# Output:
# Contiguity : 4.49
# Recent_contiguity: 2.88
# cconsistency : 3.46
# Intra consistency : 3.75
# TPCS (weighted avg of all) : 3.64
s
How does it work?
###How TPC score is calculated?
We are first extracting relevant attributes from signals with the help of sequentiality package. These attributes are:
-
total sample size (n_of_samples)
-
Longest Consecutive Subsequence of months (LCS_m)
-
Longest Consecutive Subsequence of months with 1 gap month (LCS_m_1g)
-
Longest Consecutive Subsequence of months with 2 gap month (LCS_m_1g)
-
Longest Consecutive Subsequence of months from last timestamp (LCS_m_from_last)
-
Longest Consecutive Subsequence of months from last timestamp with 1 gap month (LCS_m_from_last_1g)
-
Longest Consecutive Subsequence of months from last timestamp with 2 gap month (LCS_m_from_last_2g)
-
Longest Consecutive Subsequence of months from end time (LCS_m_from_end)
-
Longest Consecutive Subsequence of months from end time with 1 gap month (LCS_m_from_end_1g)
And then these attributes are group together into 4 features:
Consistency : shows if data collection is consistent with respect to start and end time of data crawling , (from 2020-09 to current time)
Intra Consistency : shows if data collection was consistent with respect to signal’s own start and end time.
Contiguity : shows how contiguous data is. 5 is fully contiguous which means all existed values are sequential
Recent Contiguity : shows how contiguous recent data is.
Then These features are turned into scores by calculating their ratio to max signal length and normalizing them between 0 and 5.
And we take weighted avg of these normalized scores to calculate TPC.
Features & Usage
TPC score designed as a data quality assesment for time signals. It is really easy to use.
#Lets assume we have signal of interest. TPC requires dates of this signal as input.
import datetime
date_list = ['2023-01-01', '2023-02-01', '2023-03-01', '2023-04-01', '2023-05-01', '2023-06-01', '2023-07-01', '2023-08-01', '2023-09-01', '2023-11-01', '2023-12-01', '2024-01-01']
# there are 12 months in this list. '2023-10-01' is missing.
date_list = [datetime.datetime.strptime(date_str, "%Y-%m-%d").date() for date_str in specific_dates]
weights={ "contiguity_score":0.5,
"recent_contiguity_score":3,
"consistency_score":0.8,
"intra_consistency_score":1
}
MAX_LEN_MONTHS= 13
END_OF_TIME= '2024-01-01'
tpcs =TPCS(date_list, MAX_LEN_MONTHS, END_OF_TIME=END_OF_TIME, debug=False, return_details=True)
TPC_score, tpcs_details=tpcs.calculate_TPCS(weights=weights, printing=False)
Documentation
https://github.com/karaposu/time-pattern-cohesion-score
License
MIT License
Copyright (c) 2024 Enes Kuzucu
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
Built Distribution
File details
Details for the file tpcs-0.0.5.tar.gz
.
File metadata
- Download URL: tpcs-0.0.5.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 561ece466b89ede4dc9025afea5156693d57db523ac4c5d20687563272a6de81 |
|
MD5 | e8800eff36733e955b475bd4caf2518d |
|
BLAKE2b-256 | 3b02ab26f97ee80690c3ac282f5c6b2f000558db2ec792c238a470192422445f |
File details
Details for the file tpcs-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: tpcs-0.0.5-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a080dc656baa0ea4be3185fb5081feda5afe4a050e17578c276bfe43eb03d0d |
|
MD5 | 7c210a9f7ca02ec7c78e1f7b8bac4392 |
|
BLAKE2b-256 | 721efeb9a4b56cb05bf2d2855ccf07387860fd405c77cbec925422d72cd6c548 |