Skip to main content

A general purpose stepshifting algorithm for tabular data, based on BaseEstimator.

Project description

StepShifter3 🛠️

A general purpose Python package for time series analysis of tabular data

Official Website VIEWS Forecasting Website GitHub Repo stars Twitter Follow LinkedIn Unit Tests

StepShifter3 is a Python package designed to facilitate time series analysis of tabular data. It is developed and maintained by the Peace Research Institute Oslo (PRIO) as part of the VIEWS project.

📚 Table of Contents

  1. 🛠 Installation
  2. 📝 Usage
  3. 🤝 Contributing
  4. 🔖 License
  5. ❓ FAQs
  6. 🙏 Credits
  7. 📚 References

🛠 Installation

To install StepShifter3, you have two options:

🚨 Recommended Branch: stable

For a more stable experience, we recommend using the stable branch rather than the main branch. The stable branch contains well-tested and production-ready code, while the main branch may contain work-in-progress or experimental features that could be unstable.

How to Switch to the stable branch:

Using Git CLI:

  • For pip installation, clone the stable branch directly:
    git clone -b stable https://github.com/YourUsername/StepShifter3.git
    
  • If you've already cloned the repository and are on the main branch, switch to stable with:
    git checkout stable
    

Using GitHub Web Interface:

  • If you're downloading the code from the GitHub web interface, make sure to switch to the stable branch using the branch dropdown before downloading.
  1. Using pip: 📦

    pip install StepShifter3
    
  2. From GitHub: 🐱‍💻

    git clone https://github.com/YourUsername/StepShifter3.git
    cd StepShifter3
    python setup.py install
    

📖 More Details

📝 Usage

The Stepshifter class is the main class of the package. It handles all models which is herited from the sklearn BaseEstimator class.

Basic Usage with XGBRegressor and dummy data from synthetic data generator

from StepShifter3 import StepShifter, SyntheticDataGenerator
from xgboost import XGBRegressor 

# generates a pandas multiindex dataframe with dummy data Indexes: month_id, country_id
df = SyntheticDataGenerator("cm", 516, 60000, 242).generate_dataframe()

#initialize the StepShifter3 object with the relevant parameters:
# define some XGBRegressor parameters:
params_xgb_reg = {
    'objective': 'reg:squarederror',
    'n_estimators': 500,
    'max_depth': 3,
    'learning_rate': 0.1,
    'n_jobs': -1,
    'eval_metric': 'rmse',
    'early_stopping_rounds': 30
}

stepshifter_config_xgb_reg = { "target_column" : "ln_ged_sb_dep",
                       "ID_columns" : ["month_id","country_id"],
                       "time_column" : "month_id",
                       "run_name" : 'xgb_reg_test_run_0',
                       "experiment_name" : 'xgb_reg_experiment_0',
                       "mlflow_tracking_uri" : 'http://127.0.0.1:5000',
                       "tau^e_0" : 121, # training period start
                       "tau^e_t" : 141, # training period end
                       "tau^e_c" : 146, # calibration period end
                       "tau^e_f" : 468, # forecast period end
                       "tau_f" : 516,   # Test Forfecast end 
                       "k": 13,
                       "S": 5,
                       "metrics_report": True,
                       "combine_method": 'mean_of_all',
                       }

# initialize class
stepshifter = StepShifter(XGBRegressor(**params_xgb_reg),df, stepshifter_config_xgb_reg)

# fit and predict
models = stepshifter.fit(stepshifter_config_xgb_reg['tau^e_0'],stepshifter_config_xgb_reg['tau^e_t'])
predictions = stepshifter.predict(stepshifter_config_xgb_reg['tau^e_t'],stepshifter_config_xgb_reg['tau^e_c'])

# Make model ensamble from training models and predict with a blended mean algorithm:

M_ssa = stepshifter.stepcombine()

X_test = stepshifter.X.loc[slice(136,136),slice(None),:]

# Make predictions for 1 and 3 months ahead of time:
blended_predictions = stepshifter.predict_ansamble(X_test,steps=[1,3])

🤝 Contributing

Contributions are welcome! To contribute:

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please read our Contributing Guidelines for more information.

📚 References

  1. Hegre et.al: Partitioning and time-shifting in VIEWS, fatalities002∗†

🔖 License

Distributed under the MIT License. See LICENSE for more information.

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

stepshifter3-0.1.1a0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stepshifter3-0.1.1a0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file stepshifter3-0.1.1a0.tar.gz.

File metadata

  • Download URL: stepshifter3-0.1.1a0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for stepshifter3-0.1.1a0.tar.gz
Algorithm Hash digest
SHA256 0e8a8560b377943f1e39c4f4100a35dd41cf9f8b40aab28cb88f4e4a0901b627
MD5 ca95f6202b2f556a8d2a548f1d9653b8
BLAKE2b-256 58ac009d51d4adadb10099ff2ea9b39a656149b2fa355c7323fe061dad68a0c1

See more details on using hashes here.

File details

Details for the file stepshifter3-0.1.1a0-py3-none-any.whl.

File metadata

  • Download URL: stepshifter3-0.1.1a0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for stepshifter3-0.1.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc3d29358f1b994407f84959073290f26c78ccee69ad2e24436b8dbf17574c62
MD5 6c63fd3c328839b3f2587cd481e21676
BLAKE2b-256 66b855c97bcc0ab249f0431dfc6f89783498583e6ab7640ad847232dcd7e1a94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page