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
Release history Release notifications | RSS feed
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.0.tar.gz
(4.3 kB
view details)
Built Distribution
File details
Details for the file winrollex-0.1.0.tar.gz
.
File metadata
- Download URL: winrollex-0.1.0.tar.gz
- Upload date:
- Size: 4.3 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70e38ce240e999da341c448f7bacb6b230264faf4cdf44e0447ee3486a2be36c |
|
MD5 | d65a297e329b9ec18ec3d77b2ab59e38 |
|
BLAKE2b-256 | 8d74b82a450bb908999e37828a4f423f5c3ab83234367d2a023522e535a7d14b |
File details
Details for the file winrollex-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: winrollex-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8450a6f90ba83b39d39f712b31d1e1a6479aa18ceefd7f68cf5d6845026f3e6e |
|
MD5 | 1b3d05a0fd4a1f451576c444839a3848 |
|
BLAKE2b-256 | 532584844a606097d83c241bf6c3612b3bf2bc2e2c922c54d315baf22dc94b2d |