Skip to main content

Verify causal graph from data-driven models

Project description

Forecast Verifier

Forecast verifier is Python package for verifying specified causal relationships between forecasts/predictions and covariates given trained models. The package goes one step beyond simple model explainability tools to extract learnt causal relationships, and verify them against existing domain knowledge.

Documentation can be found at: [Homepage] https://maichi-bui.github.io/forecast-verifier

Installation

Install the forecast_verifier package using pip command:

pip install forecast-verifier

Usage example

import pandas as pd
from forecast_verifier.model import Forecaster, Regressor
from forecast_verifier.dataset import PerturbationDataset
from forecast_verifier.verifier import Verifier
from forecast_verifier.graph import PerturbationDirection, EffectDirection

# Create your model inheriting from Forecaster or Regressor that implements the forecast/predict method
class CustomForecaster(Forecaster):
    def __init__(self):
        super().__init__()
        # Initialize your model here    
    def forecast(self, dataset):
        # Implement your forecasting logic here
        pass

my_model = CustomForecaster()

# Load your dataset
original_data = pd.read_csv('your_dataset.csv')
pertubation_data = pd.read_csv('your_pertubation_dataset.csv')

# if pertubation_data are not available, create a PerturbationDataset based on original_data
perturbation_data = PerturbationDataset(original_dataset=original_data, 
                                        covariates=['covariate1'], 
                                        perturbation_direction=PerturbationDirection.increasing)
# increase covariate1 by 20% with bounds (-10, 40)
perturbation_data = perturbation_data.multipicative_perturb(0.2, bound=(-10, 40))
# increase covariate1 by 10 units with bounds (-10, 40)
perturbation_data = perturbation_data.additive_perturb(10, bound=(-10, 40))

# Define and verify causal relationships
## when covariate1 increases, the forecast should decrease, i.e., negative effect
## perturbation direction is increasing, meaning that we increase covariate1 from original_data to pertubation_data
verifier = Verifier(model=my_model, 
                    original_dataset=original_data, 
                    perturbed_dataset=pertubation_data, 
                    covariates=['covariate1'],                     
                    effect_direction=EffectDirection.negative,
                    perturbation_direction=PerturbationDirection.increasing)

print(verifier())

Check out other examples in examples/ folder

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

forecast_verifier-0.1.2.tar.gz (5.4 MB view details)

Uploaded Source

Built Distribution

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

forecast_verifier-0.1.2-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file forecast_verifier-0.1.2.tar.gz.

File metadata

  • Download URL: forecast_verifier-0.1.2.tar.gz
  • Upload date:
  • Size: 5.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for forecast_verifier-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e3748389e5fb9b9958b9a33d3b8483bca91ee7eceddf446f51b135cae86264df
MD5 5163d61f0daf07f05451d8d30cadf658
BLAKE2b-256 77caa9623e6827d784d658bcf91293297c13001a981a76fe4b538c7d8add319e

See more details on using hashes here.

File details

Details for the file forecast_verifier-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for forecast_verifier-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ef51790b4451db9d8ff837310f37de12f36cb1e37a0d81dbcd6e88760f81fedd
MD5 6a23c7db4a808b2d58d16c0cd9456192
BLAKE2b-256 8e1f24adf5ea7fcf06f6bbf925df298a3e00f7db208ba7fac21373daefb6b165

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