DATFID Python Package

Interpretable AI forecasting for Python

Installation

Terminal
pip install datfid

Example 1: Revenue Forecasting

Forecast revenue for products in the food and beverages industry.

Python - Step 1
import pandas as pd
from datfid import DATFIDClient

# Initialize the client
client = DATFIDClient(token="your_DATFID_token")
  • Import the necessary libraries and initialize the DATFID client with your API token
  • This creates a connection to the DATFID API that you'll use for model fitting and forecasting
Python - Step 2
# 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 your training dataset and fit the model using the fit_model method
  • Required parameters:
    id_col
    time_col
    y
  • Optional parameters:
    current_features
    filter_by_significance
  • The current_features parameter is optional — in this example, we set it to 'all' to use all available columns in the dataset as features
Python - Step 3
# 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
forecast = client.forecast_model(df_forecast=df_forecast)
  • Load your forecast dataset and generate predictions using the trained model
  • The forecast_model method uses the previously fitted model to predict future revenue values based on the features in your forecast dataset

Example 2: Loan Probability Forecasting

Predict loan probabilities in the banking sector with lagged features.

Python - Step 1
import pandas as pd
from datfid import DATFIDClient

# Initialize the client
client = DATFIDClient(token="your_DATFID_token")
  • Import the necessary libraries and initialize the DATFID client with your API token
  • This creates a connection to the DATFID API that you'll use for model fitting and forecasting
Python - Step 2
# 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 with lagged features
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 your training dataset and fit the model using the fit_model method
  • Required parameters:
    id_col
    time_col
    y
  • Optional parameters:
    lag_y
    lagged_features
    filter_by_significance
  • Historical data parameters: Both lag_y and lagged_features control how much historical data is taken into consideration for the analysis (the lag)
  • lag_y="1:3" means 3 lags (lag 1, lag 2, and lag 3) of the target variable
  • lagged_features={"Income Level": "1:3"} means the "Income Level" feature will include 3 historical lags
Python - Step 3
# 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
forecast = client.forecast_model(df_forecast=df_forecast)
  • Load your forecast dataset and generate predictions using the trained model
  • The forecast_model method uses the previously fitted model (including the lagged features) to predict future loan probability values based on the features in your forecast dataset

Ready to Get Started?

Get instant access to the DATFID API with our free trial. No credit card required.

The official DATFID Python package is available on PyPI for easy installation.