Skip to main content

Simple [temporal] rolling and expanding windows for machine learning applicationsn

Project description

WinRollEx

Introduction

WinRollEx is a simple rolling and expanding windows for machine learning applications. It supports both temporal and spatial window types.

Installation

WinRollEx can be installed using the following command:

pip install winrollex

Usage

import winrollex as wrx
import pandas as pd
import numpy as np

# Create a DataFrame
df = pd.DataFrame(np.random.randn(1000, 4))
print(df.head(10))

# Create a window generator
window = wrx.Window(df)

# Rolling Window
# using training_window_size, test_window_size and window_increment
for train, test in window.rolling(training_window_size=200, test_window_size=100, window_increment=50):
    print(train)
    print(test)

# using training_window_size and test_window_size.
# Note: if window_increment is not set, it will assume the value of test_window_size.
for train, test in window.rolling(training_window_size=200, test_window_size=100):
    print(train)
    print(test)

# using training_window_size and iterations
# Note: the test_window_size and window_increment are ignored when iterations is set and will assume the value of
# (dataset_size - training_window_size) / iterations.
for train, test in window.rolling(training_window_size=200, iterations=10):
    print(train)
    print(test)

# using training_window_size, test_window_size and window_increment as a % of the dataset size
for train, test in window.rolling(training_window_size=0.3, test_window_size=0.1, window_increment=0.1):
    print(train)
    print(test)

# using training_window_size as a % of the dataset size and iterations
for train, test in window.rolling(training_window_size=0.3, iterations=10):
    print(train)
    print(test)

# Expanding Window
# using training_window_size, test_window_size and window_increment
for train, test in window.expanding(training_window_size=200, test_window_size=100, window_increment=50):
    print(train)
    print(test)

# using training_window_size and test_window_size.
# Note: if window_increment is not set, it will assume the value of test_window_size.
for train, test in window.expanding(training_window_size=200, test_window_size=100):
    print(train)
    print(test)

# using training_window_size and iterations
# Note: the test_window_size and window_increment are ignored when iterations is set and will assume the value of
# (dataset_size - training_window_size) / iterations.
for train, test in window.expanding(training_window_size=200, iterations=10):
    print(train)
    print(test)

# using training_window_size, test_window_size and window_increment as a % of the dataset size
for train, test in window.expanding(training_window_size=0.3, test_window_size=0.1, window_increment=0.1):
    print(train)
    print(test)

# using training_window_size as a % of the dataset size and iterations
for train, test in window.expanding(training_window_size=0.3, iterations=10):
    print(train)
    print(test)

# Temporal Rolling Window
# Note: for temporal windows, it is assumed that the dataframe index is a datetime
df = pd.DataFrame(np.random.randn(1000, 4), index=pd.date_range('1/1/2000', periods=1000))

# The windows are either pandas.Timedelta, datetime.timedelta or dateutils.relativedelta objects.
training_delta = pd.Timedelta(days=200)
test_delta = pd.Timedelta(days=100)
increment_delta = pd.Timedelta(days=50)

# using training_window_size, test_window_size and timedelta
for train, test in window.temporal_rolling(training_window_size=training_delta, test_window_size=test_delta, timedelta=increment_delta):
    print(train)
    print(test)

# using training_window_size and test_window_size.
# Note: if timedelta is not set, it will assume the value of test_window_size.
for train, test in window.temporal_rolling(training_window_size=training_delta, test_window_size=test_delta):
    print(train)
    print(test)

# using training_window_size and iterations
# Note: the test_window_size and timedelta are ignored when iterations is set and will assume the value of
# ((end_date - start_date) - training_window_size) / iterations.
for train, test in window.temporal_rolling(training_window_size=training_delta, iterations=10):
    print(train)
    print(test)

# using training_window_size, test_window_size and timedelta as a % of the dataset size
for train, test in window.temporal_rolling(training_window_size=0.3, test_window_size=0.1, timedelta=increment_delta):
    print(train)
    print(test)

# using training_window_size as a % of the dataset size and iterations
for train, test in window.temporal_rolling(training_window_size=0.3, iterations=10):
    print(train)
    print(test)

# Temporal Expanding Window
# using training_window_size, test_window_size and timedelta
for train, test in window.temporal_expanding(training_window_size=training_delta, test_window_size=test_delta, timedelta=increment_delta):
    print(train)
    print(test)

# using training_window_size and test_window_size.
# Note: if timedelta is not set, it will assume the value of test_window_size.
for train, test in window.temporal_expanding(training_window_size=training_delta, test_window_size=test_delta):
    print(train)
    print(test)

# using training_window_size and iterations
# Note: the test_window_size and timedelta are ignored when iterations is set and will assume the value of
# ((end_date - start_date) - training_window_size) / iterations.
for train, test in window.temporal_expanding(training_window_size=training_delta, iterations=10):
    print(train)
    print(test)

# using training_window_size and test_window_size as a % of the dataset size
for train, test in window.temporal_expanding(training_window_size=0.3, test_window_size=0.1, timedelta=increment_delta):
    print(train)
    print(test)

# using training_window_size as a % of the dataset size and iterations
for train, test in window.temporal_expanding(training_window_size=0.3, iterations=10):
    print(train)
    print(test)

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

winrollex-0.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

winrollex-0.1.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file winrollex-0.1.1.tar.gz.

File metadata

  • Download URL: winrollex-0.1.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/5.4.0-187-generic

File hashes

Hashes for winrollex-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b082ad053c2daacea96edff3818440a1370b81ba908ead7c89b55f40db492b9e
MD5 5c8753b1886921c780a066079e25b5bc
BLAKE2b-256 ac3c9691329691ff1a57e37b84316387a148045a9ccf1d7c09d6d6f2f8684b82

See more details on using hashes here.

File details

Details for the file winrollex-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: winrollex-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/5.4.0-187-generic

File hashes

Hashes for winrollex-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8eabe39fda29eed827998015b30ebc7d1137d726c3c1701d51e6a8625f8d227c
MD5 4f35d366d0da43b0f61b297fc5ca610e
BLAKE2b-256 55ae92aa6e689b8a0cbedb9e7a85bad14d255b02b5e0a480bdf290b924356e8f

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