This is a Python port of the R package greybox - a toolbox for model building and forecasting. The original R package implements functions and instruments for regression model building and its application to forecasting.
- Regression Models: Advanced Linear Model (ALM), Scale Model (SM), Dynamic Linear Regression
- Model Selection: Stepwise regression based on information criteria, partial correlations. Combined ALM (CALM)
- Variable Processing:
- Lag/lead expansion (
xregExpander) - Mathematical transformations (log, sqrt, etc.)
- Cross-product generation
- Temporal dummies, outlier dummies
- Lag/lead expansion (
- Forecasting: Rolling origin evaluation, error measures
- Statistical Measures: AIC, BIC, determination coefficients, association measures
- Bootstrap Methods: Parameter bootstrap, bootstrap for time series
- Distributions: Normal, Laplace, LogitNormal, Beta-Normal, etc.
- Data scientists and forecasters
- Marketing analysts
- Econometric modelers
- Anyone building predictive models with time series data
These commands ensure your code adheres to standards and functions as expected.
IMPORTANT: Always use the python/.venv environment when running Python commands!
Example:
cd python && .venv/bin/python -m pytest tests/make buildThis command compiles the project. Ensure you're in the root directory of the project before running it. Lint Command:
flake8 .The flake8 tool checks your Python code for issues, including errors and deviations from PEP 8 style guidelines. It's a combination of PyFlakes, pycodestyle (formerly pep8), and McCabe script. Test Commands:
- Run all tests:
pytest- Run tests in watch mode:
ptwThis command runs pytest in a loop, re-running the tests whenever one of your files changes.
- Run tests in watch mode:
- Run a specific test file:
pytest [path_to_test_file]- Run a specific test within a test file:
pytest [path_to_test_file]::[TestClassOrFunctionName]
- Run a specific test within a test file:
- Place standard library imports first, then third-party libraries, and lastly the local application/library-specific imports. Each section should be separated by an empty line.
Example:
import os
import sys
import requests
from flask import Flask
from myapp.forms import MyForm- Use 4 spaces per indentation level.
- Ensure lines do not exceed 80 characters to prevent horizontal scrolling.
- Separate top-level function and class definitions with two blank lines, and method definitions inside a class body with one blank line.
- Surround binary operators (+, -, *, / etc) with a single space on either side for readability. Types Enforce type hints in your codebase to improve readability and maintainability. This helps tools like mypy (used for static type checking). Example:
def multiply(a: int, b: int) -> int:
return a * b##Naming Conventions
- Variables: Use lowercase with words separated by underscores.
max_retries = 3- Constants: Capitalize each word and separate using underscores.
MAX_CONNECTIONS = 100 - Functions & Methods: Lowercase with words separated by underscores.
- Constants: Capitalize each word and separate using underscores.
def send_email(to_address: str, body: str) -> None:
pass- Classes: Capitalize the first letter of each word (CamelCase).
class UserAuthenticator:
pass
Handle exceptions gracefully. Use specific exceptions rather than catching a broad Exception which can hide many errors.
Example:
try:
response = requests.get('https://api.example.com/data')
response.raise_for_status()
except requests.exceptions.HTTPError as e:
print(f"HTTP error occurred: {e}")