TimeMesh
A Python library for time series data preprocessing featuring advanced windowing strategies, normalization, and dataset splitting. Perfect for preparing time-dependent data for LSTM, Transformer, and other sequence models.
Install / Use
/learn @L-A-Sandhu/TimeMeshREADME
Timemesh 🕰️
A Python library for time series data preprocessing featuring advanced windowing strategies, normalization, and dataset splitting. Perfect for preparing time-dependent data for LSTM, Transformer, and other sequence models.
🚀 Key Features for Time Series Machine Learning
- ⏳ Temporal Windowing: Create overlapping/non-overlapping windows for RNN/LSTM/Transformer models
- 🔢 Smart Normalization: Min-Max & Z-score scaling with automatic denormalization
- ✂️ Dataset Splitting: Time-aware train/validation/test splits for temporal data
- 🛠️ Production-Ready: Built-in data validation & modular pipeline architecture
- 🔄 End-to-End Workflow: From raw CSV to model-ready sequences in 5 lines of code
Perfect for: Weather forecasting, stock prediction, IoT sensor analysis, and any time-series forecasting tasks
🔍 Why Timemesh vs Other Libraries?
| Feature | Timemesh | TensorFlow Window | PyTorch DataLoader | |------------------------|----------|-------------------|--------------------| | Built-in Normalization | ✅ | ❌ | ❌ | | Time-aware Splitting | ✅ | ❌ | ❌ | | Multi-Output Support | ✅ | ❌ | Limited | | Denormalization | ✅ | ❌ | ❌ | | Data Validation | ✅ | ❌ | ❌ |
🌐 Real-World Use Cases
⚡ Energy Demand Forecasting
loader = tm.DataLoader(
T=168, # 1 week of hourly data
H=24, # Predict next day's demand
norm="Z",
ratio={'train': 70, 'test': 15, 'valid': 15}
)
Installation
pip install timemesh
Quick Start
import timemesh as tm
# Initialize data loader
loader = tm.DataLoader(
T=24, # Use 24 historical steps
H=6, # Predict 6 steps ahead
input_cols=["temperature", "humidity"],
output_cols=["target_feature"],
norm="MM" # Min-Max normalization,
ratio={'train': 70, 'test': 15, 'valid': 15}
)
# Load and preprocess data
X, Y, input_params, output_params = loader.load_csv("data.csv")
| Parameter | Description | Default | Options |
|---------------|--------------------------------------|---------|-----------------------|
| T | Historical time steps per sample | 1 | Any positive integer |
| H | Prediction horizon steps | 1 | Any positive integer |
| input_cols| Features used for model input | None(All will be input) | List of column names |
| output_cols| Target features for prediction | None(All Will be output | List of column names |
| norm | Normalization method | None(No Normalization) | "MM", "Z" |
| steps | Step size between windows | None(Non overlapping) | Any positive integer |
| ratio | Train, Test and Validation Split | None(No Split Just get X and Y) | Any positive integer |
Example Usage Code
Download Example dataset
wget https://github.com/L-A-Sandhu/TimeMesh/blob/main/examples/data.csv
Complete Functional Example Load , Normalize and Split data
# =================================================================
# Complete Functional Example Load , Normalize and Split data
# =================================================================
input_cols = [
"C_WD50M", "C_WS50M", "C_PS", "C_T2M", "C_QV2M",
"N_WD50M", "N_WS50M", "N_PS", "N_T2M", "N_QV2M",
"S_WD50M", "S_WS50M", "S_PS", "S_T2M", "S_QV2M",
"E_WD50M", "E_WS50M", "E_PS", "E_T2M", "E_QV2M",
"W_WD50M", "W_WS50M", "W_PS", "W_T2M", "W_QV2M",
"NE_WD50M", "NE_WS50M", "NE_PS", "NE_T2M", "NE_QV2M",
"NW_WD50M", "NW_WS50M", "NW_PS", "NW_T2M", "NW_QV2M",
"SE_WD50M", "SE_WS50M", "SE_PS", "SE_T2M", "SE_QV2M",
"SW_WD50M", "SW_WS50M", "SW_PS", "SW_T2M", "SW_QV2M"
]
output_cols = ["C_WS50M"]
print("\n--- Case 2: With Min-Max Normalization ---")
loader_norm = tm.DataLoader(T=24, H=6, input_cols=input_cols, output_cols=output_cols, norm="Z",step=12, ratio={'train': 70, 'test': 15, 'valid': 15})
X_train, Y_train, X_test, Y_test, X_valid, Y_valid, input_params, output_params = loader_norm.load_csv("data.csv")
print("\nLoaded normalized data:")
print(f"Shape of X_train: {X_train.shape}")
print(f"Shape of Y_train: {Y_train.shape}")
print(f"Shape of X_test: {X_test.shape}")
print(f"Shape of Y_test: {Y_test.shape}")
print(f"Shape of X_valid: {X_valid.shape}")
print(f"Shape of Y_valid: {Y_valid.shape}")
Case 1: Without Normalization (norm=None)
import timemesh as tm
import numpy as np
import pandas as pd
# =================================================================
# Load your data for verification
# =================================================================
input_cols = ["C_WD50M", "C_WS50M", "C_PS", "C_T2M", "C_QV2M", "N_WD50M", "N_WS50M", "N_PS", "N_T2M", "N_QV2M"]
output_cols = ["C_WS50M", "N_WS50M", "S_WS50M", "E_WS50M", "W_WS50M"]
# =================================================================
# Case 1: Without Normalization (norm=None)
# =================================================================
print("\n--- Case 1: Without Normalization ---")
loader_raw = tm.DataLoader(T=24, H=6, input_cols=input_cols, output_cols=output_cols, norm=None)
X_raw, Y_raw = loader_raw.load_csv("data.csv")
print("\nLoaded raw data:")
print(f"Shape of X_raw: {X_raw.shape}")
print(f"Shape of Y_raw: {Y_raw.shape}")
print(f"First sample of X_raw:\n{X_raw[0]}")
print(f"First sample of Y_raw:\n{Y_raw[0]}")
Case 2: With Min-Max Normalization
# =================================================================
# Case 2: With Min-Max Normalization
# =================================================================
print("\n--- Case 2: With Min-Max Normalization ---")
loader_norm = tm.DataLoader(T=24, H=6, input_cols=input_cols, output_cols=output_cols, norm="MM")
X_norm, Y_norm, input_params, output_params = loader_norm.load_csv("data.csv")
print("\nLoaded normalized data:")
print(f"Shape of X_norm: {X_norm.shape}")
print(f"Shape of Y_norm: {Y_norm.shape}")
print(f"Normalization parameters (input):\n{input_params}")
print(f"Normalization parameters (output):\n{output_params}")
print(f"First sample of X_norm:\n{X_norm[0]}")
print(f"First sample of Y_norm:\n{Y_norm[0]}")
Case 2: With Min-Max Normalization
# =================================================================
# Denormalize the normalized data
# =================================================================
print("\n--- Denormalizing the normalized data ---")
X_denorm = tm.Normalizer.denormalize(
X_norm, params=input_params, method="MM", feature_order=input_cols # Must match original order
)
Y_denorm = tm.Normalizer.denormalize(Y_norm, params=output_params, method="MM", feature_order=output_cols)
print("\nDenormalized data:")
print(f"Shape of X_denorm: {X_denorm.shape}")
print(f"Shape of Y_denorm: {Y_denorm.shape}")
print(f"First sample of X_denorm:\n{X_denorm[0]}")
print(f"First sample of Y_denorm:\n{Y_denorm[0]}")
Case 2: With Min-Max Normalization
# =================================================================
# Verification Checks
# =================================================================
def verify_results():
print("\n--- Verification Results ---")
# Check 1: Raw vs Denormalized should match exactly
x_match = np.allclose(X_raw, X_denorm, atol=1e-4)
y_match = np.allclose(Y_raw, Y_denorm, atol=1e-4)
print(f"X Match (Raw vs Denorm): {x_match}")
print(f"Y Match (Raw vs Denorm): {y_match}")
# Check 2: Normalized vs Raw ranges
print("\nNormalization Ranges:")
print(f"X_norm range: [{X_norm.min():.2f}, {X_norm.max():.2f}]")
print(f"Y_norm range: [{Y_norm.min():.2f}, {Y_norm.max():.2f}]")
# Check 3: Sample value comparison
sample_idx = 0 # First sample
time_idx = 0 # First timestep
feature_idx = 1 # C_WS50M
print("\nSample Value Comparison:")
print(f"Original (Raw): {X_raw[sample_idx, time_idx, feature_idx]:.2f}")
print(f"Denormalized: {X_denorm[sample_idx, time_idx, feature_idx]:.2f}")
print(f"Normalized: {X_norm[sample_idx, time_idx, feature_idx]:.2f}")
verify_results()
Case 3: Test with norm=None (No normalization, No Split)
# =================================================================
# Case 3: Test with norm=None (No normalization, No Split)
# =================================================================
def test_no_normalization():
print("\n--- Case 3: Test with No Normalization ---")
loader = tm.DataLoader(T=24, H=6, input_cols=input_cols, output_cols=output_cols, norm=None)
X, Y = loader.load_csv("data.csv")
# Directly compare with raw data from CSV
expected_X = df[input_cols].values[:24] # First window
assert np.allclose(X[0], expected_X), "No normalization should return raw data"
print("\nTest Passed: No normalization returns raw data successfully.")
test_no_normalization()
Case 4: With Z-Score Normalization
# =================================================================
# Case 4: With Z-Score Normalization
# =================================================================
print("\n--- Case 4: With Z-Score Normalization ---")
loader_z = tm.DataLoader(T=24, H=6, input_cols=input_cols, output_cols=output_cols, norm="Z") # Z-score normalization
X_norm_z, Y_norm_z, input_params_z, output_params_z = loader_z.load_csv("data.csv")
print("\nLoaded Z-normalized data:")
print(f"Shape of X_norm_z: {X_norm_z.shape}")
print(f"Shape of Y_norm_z: {Y_norm_z.shape}")
pri
Related Skills
proje
Interactive vocabulary learning platform with smart flashcards and spaced repetition for effective language acquisition.
YC-Killer
2.7kA library of enterprise-grade AI agents designed to democratize artificial intelligence and provide free, open-source alternatives to overvalued Y Combinator startups. If you are excited about democratizing AI access & AI agents, please star ⭐️ this repository and use the link in the readme to join our open source AI research team.
best-practices-researcher
The most comprehensive Claude Code skills registry | Web Search: https://skills-registry-web.vercel.app
groundhog
400Groundhog's primary purpose is to teach people how Cursor and all these other coding agents work under the hood. If you understand how these coding assistants work from first principles, then you can drive these tools harder (or perhaps make your own!).
