blocks-transformer/graph_processing.py
admin user 62dfadde20
All checks were successful
Build and Push Docker Image / test (push) Successful in 50s
Build and Push Docker Image / build_and_push (push) Successful in 2m21s
Advanced Graph Series model
2025-03-12 16:13:29 +00:00

35 lines
854 B
Python

import xgboost as xgb
import pandas as pd
import joblib
import logging
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
)
logger = logging.getLogger(__name__)
def processing(data):
df = pd.DataFrame([data])
if df.empty:
logger.error("Input DataFrame is empty.")
# Load Model
model_path = "./xgboost_model.joblib"
# model_path ="C:/Users/abinisha/habemco_flowx/g1_v1/xgboost_model.joblib"
model = joblib.load(model_path)
expected_features = model.feature_names
df = df.applymap(lambda x: float('nan') if x is None else x)
dmatrix = xgb.DMatrix(df[expected_features], enable_categorical=True, missing=float('nan'))
prediction = model.predict(dmatrix)
df['prediction'] = prediction
return df.iloc[0].to_dict()