Skip to main content

SDK to access the DATFID API hosted on Hugging Face Spaces

Project description

DATFID SDK

A Python SDK to access the DATFID API to forecast your data.

Features

  • Easy model fitting: Build panel data models with time-dependent and static features.
  • Flexible lag handling: Specify lags for the dependent variable and selected features.
  • Forecasting: Generate future predictions with aligned timestamps and IDs.
  • Statistical options: Filter features by significance and apply mean-variance tests.
  • White box full interpretability: Get fully interpretable model with equation, estimated parameters, and standard errors.

Installation

pip install datfid

Usage

Before using the SDK, please request an access token by emailing admin@datfid.com or by visiting our website datfid.com.

from datfid import DATFIDClient

# Initialize the client with your DATFID token
client = DATFIDClient(token="your_DATFID_token")

# Fit a model
fit_result = client.fit_model(
    df=dataframe,
    id_col="name of id column",
    time_col="name of time column",
    y="name of dependent variable",
    lag_y="starting lag : ending lag",
    lagged_features={
        "feature 1": "starting lag : ending lag",
        "feature 2": "starting lag : ending lag"
    },
    current_features=["feature 3", "feature 4"],
    filter_by_significance=True/False,
    meanvar_test=True/False
)

# Generate forecasts
forecast_df = client.forecast_model(
    df_forecast=dataframe
)

# The forecast DataFrame contains the individual IDs and timestamps
# from the original data plus a "forecast" column with predicted values.

Example 1

Sample dataset from GitHub (Food and Beverages demand forecasting):

import pandas as pd
from datfid import DATFIDClient

# Initialize the client with your DATFID token
client = DATFIDClient(token="your_DATFID_token")

# Load dataset for model fitting
url_fit = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Food_Beverages.xlsx"
df = pd.read_excel(url_fit)

# Fit the model
result = client.fit_model(df=df,
                          id_col="Product",
                          time_col="Time",
                          y="Revenue",
                          current_features='all',
                          filter_by_significance=True
                          )

# Load dataset for forecasting
url_forecast = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Food_Beverages_forecast.xlsx"
df_forecast = pd.read_excel(url_forecast)

# Forecast revenue using the fitted model
forecast = client.forecast_model(df_forecast=df_forecast)

Example 2

Slightly larger sample dataset from GitHub (Banking sector, forecasting loan probability):

import pandas as pd
from datfid import DATFIDClient

# Initialize the client with your DATFID token
client = DATFIDClient(token="your_DATFID_token")

# Load dataset for model fitting
url_fit = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Banking_extended.xlsx"
df = pd.read_excel(url_fit)

# Fit the model
result = client.fit_model(df=df,
                          id_col="Individual",
                          time_col="Time",
                          y="Loan Probability",
                          lag_y="1:3",
                          lagged_features={"Income Level": "1:3"},
                          filter_by_significance=True)

# Load dataset for forecasting
url_forecast = "https://raw.githubusercontent.com/datfid-valeriidashuk/sample-datasets/main/Banking_extended_forecast.xlsx"
df_forecast = pd.read_excel(url_forecast)

# Forecast loan probability using the fitted model
forecast = client.forecast_model(df_forecast=df_forecast)

API Reference

DATFIDClient

client = DATFIDClient(token: str)

Initialize the client with your DATFID token.

client.fit_model(df: pd.DataFrame, id_col: str, time_col: str, y: str, lag_y: Optional[Union[int, str, list[int]]] = None, lagged_features: Optional[Dict[str, int]] = None, current_features: Optional[list] = None, filter_by_significance: bool = False, meanvar_test: bool = False) -> SimpleNamespace

Fit a model using the provided dataset.

client.forecast_model(df_forecast: pd.DataFrame) -> pd.DataFrame

Generate forecasts using the fitted model.

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

datfid-0.1.22.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

datfid-0.1.22-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file datfid-0.1.22.tar.gz.

File metadata

  • Download URL: datfid-0.1.22.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for datfid-0.1.22.tar.gz
Algorithm Hash digest
SHA256 69a11f25f2af5fc3dcfe75041935297b91082e91d4f66e80e36e9fe9830ce0f9
MD5 1e4cbf7fe1cda65f74f4d47af3a41e2e
BLAKE2b-256 8a0ba6448ddd284ed45a0b1e77773489beeb1bb5708409e973eb52996447e0f9

See more details on using hashes here.

File details

Details for the file datfid-0.1.22-py3-none-any.whl.

File metadata

  • Download URL: datfid-0.1.22-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for datfid-0.1.22-py3-none-any.whl
Algorithm Hash digest
SHA256 037c8a837013e0b1e6fffdc154c3b5e53fdeac84ac935fbb5dd4d7310f1be87f
MD5 7f9dd5b0acb771197eeeef4f0c5ecf60
BLAKE2b-256 8ee805a46965afc007843aa8cc9b10e739fbdb1ef95e7c0de98bba698be90edc

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