https://github.com/acaciaman/time-decomp

Time series decomposition plot trend and seasonality

https://github.com/acaciaman/time-decomp

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: mdpi.com
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (6.4%) to scientific vocabulary

Keywords

decomposition plot seasonal time-series trend
Last synced: 6 months ago · JSON representation

Repository

Time series decomposition plot trend and seasonality

Basic Info
  • Host: GitHub
  • Owner: AcaciaMan
  • License: apache-2.0
  • Language: Jupyter Notebook
  • Default Branch: main
  • Homepage:
  • Size: 61.5 KB
Statistics
  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 14
Topics
decomposition plot seasonal time-series trend
Created over 1 year ago · Last pushed 12 months ago
Metadata Files
Readme License

README.md

time-decomp

Time series decomposition plot trend and seasonality

Plot trend and seasonality together in one chart as described at Business Days Time Series Weekly Trend and Seasonality.

PyPI Downloads PyPI Downloads PyPI Downloads

Added SARIMAX keew predictions (see sarimaxtest.py testplot_keew())

Screenshot_sarimax

Example usage from ./Python/tests/keewdecomptest.py

```

create test

test_decomposition.py

import unittest import pandas as pd import numpy as np import matplotlib.pyplot as plt from time_decomp.decomposition import DecompositionSingleton

class TestKeewDecomposition(unittest.TestCase): def setUp(self): self.decomp = DecompositionSingleton()

    n = 2000

    df = pd.DataFrame({'A': np.random.randint(0,100, size=(n,)), 'B': np.random.randint(0,100, size=(n,))})

    lsDays = [pd.Timestamp(2021, 1, 1)]*n
    for i in range(n):
        # construct time, where iYear-iMonth-i
        lsDays[i] = pd.Timestamp( np.random.randint(2021,2025), np.random.randint(1,13) , (i+1) % 28 + 1)    

    df['Day'] = lsDays

    df['Year'] = df['Day'].dt.year
    df['Month'] = df['Day'].dt.month
    df['KeewMonth'] = df['Day'].apply(self.decomp.get_month_keew)
    df['Keew']=(df['Month']-1)*4+df['KeewMonth']

    self.decomp.df = df.groupby(['Year', 'Keew']).last().reset_index()

    self.decomp.features = ['A', 'B']
    self.decomp.decompose_params = {'model': 'additive', 'period':48, 'extrapolate_trend':'freq'}        

def test_plot_decomposition(self):

    # output df info
    print("Starting test_plot_decomposition")
    print("DataFrame Info:")
    print(self.decomp.df.info())
    print("DataFrame Head:")
    print("\n%s", self.decomp.df.head())


    self.decomp.m_decompose()
    self.decomp.plot_decomposition('A', 'Year', range(2021,2025), 'Keew', 'A keew', chart_elements=[self.decomp.ChartElement.TREND, self.decomp.ChartElement.SEASONAL])
    plt.show()

```

Added PLOTLY to run from IPython Notebook

``` from plotly.offline import iplot

decomp.mdecompose() fig = decomp.plotdecompositionplotly('A', 'Year', range(2021,2025), 'Keew', 'A keew', chartelements=[ decomp.ChartElement.OBSERVED, decomp.ChartElement.SEASONAL]) iplot(fig) ```

Added trends analysis from EnvironmentalTrends

``` from time_decomp.environmentaltrends import EnvironmentalTrends

Set pandas option to display all columns

pd.setoption('display.maxcolumns', None)

class TestEnvironmentalTrends(unittest.TestCase):

def setUp(self):
    self.decomp = EnvironmentalTrends()
    self.decomp.features = ['A']
    self.decomp.trend_data_params = {'year_col':'Year', 'month_col':'Month' }
    self.decomp.trends_params = {'seasons_per_year': 12, 'trend_lengths': [1], 'end_years': [2025]}

def test_m_trends(self):
    self.decomp.m_trends()
    # output df info
    print("Starting test_plot_decomposition")
    print("DataFrame Info:")
    print(self.decomp.t['A'].info())
    print("DataFrame Head:")
    print("\n%s", self.decomp.t['A'].head())

```

``` DataFrame Head:

%s Frequency SeasonsPeryear TrendLength TrendEnd TrendPeriod \ 0 Monthly 12 1 2025 Jul 2024 to Jun 2025

ValueCount Minimum Median Average Maximum YearsInPeriod \ 0 12.0 5.0 48.0 50.333333 96.0 1.0

SeasonsInPeriod PercentOfYears PercentOfSeasons KW-pValue Seasonality \ 0 12.0 100.0 100.0 0.443263 Non-seasonal

AppliedSeasonality MK-S MK-Variance MK-pvalue IncreasingLikelihood \ 0 Non-seasonal 8.0 212.666667 0.631222 68.438909

  TrendDirection  SenSlope  LowerSlope  UpperSlope  

0 Likely increasing 16.5 -384.0 544.8 ```

Owner

  • Login: AcaciaMan
  • Kind: user

GitHub Events

Total
  • Release event: 4
  • Watch event: 1
  • Push event: 7
  • Create event: 4
Last Year
  • Release event: 4
  • Watch event: 1
  • Push event: 7
  • Create event: 4

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 45 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 10
  • Total maintainers: 1
pypi.org: time-decomp

Time series decomposition plot trend and seasonality together

  • Versions: 10
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 45 Last month
Rankings
Dependent packages count: 10.3%
Average: 34.2%
Dependent repos count: 58.1%
Maintainers (1)
Last synced: 6 months ago