Skip to main content

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.

TPCS

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:

  1. total sample size (n_of_samples)

  2. Longest Consecutive Subsequence of months (LCS_m)

  3. Longest Consecutive Subsequence of months with 1 gap month (LCS_m_1g)

  4. Longest Consecutive Subsequence of months with 2 gap month (LCS_m_1g)

  5. Longest Consecutive Subsequence of months from last timestamp (LCS_m_from_last)

  6. Longest Consecutive Subsequence of months from last timestamp with 1 gap month (LCS_m_from_last_1g)

  7. Longest Consecutive Subsequence of months from last timestamp with 2 gap month (LCS_m_from_last_2g)

  8. Longest Consecutive Subsequence of months from end time (LCS_m_from_end)

  9. 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.

Metadata

Release files for tpcs 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tpcs 0.0.5
File Size Uploaded
tpcs-0.0.5.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tpcs 0.0.5
File Interpreter ABI Platform
tpcs-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / tpcs-0.0.5.tar.gz

Download URL tpcs-0.0.5.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
561ece466b89ede4dc9025afea5156693d57db523ac4c5d20687563272a6de81
BLAKE2b-256 checksum
How to use checksums
3b02ab26f97ee80690c3ac282f5c6b2f000558db2ec792c238a470192422445f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.7

Release files / tpcs-0.0.5-py3-none-any.whl

Download URL tpcs-0.0.5-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a080dc656baa0ea4be3185fb5081feda5afe4a050e17578c276bfe43eb03d0d
BLAKE2b-256 checksum
How to use checksums
721efeb9a4b56cb05bf2d2855ccf07387860fd405c77cbec925422d72cd6c548
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page