35 lines
854 B
Python
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()
|