StrokeLineAI / utils.py
DeepActionPotential's picture
Upload folder using huggingface_hub
da0d126 verified
raw
history blame contribute delete
926 Bytes
import pandas as pd
def preprocess_input(data: dict) -> pd.DataFrame:
"""
Build a single-row DataFrame matching the training schema:
['gender','age','hypertension','heart_disease','ever_married',
'work_type','Residence_type','avg_glucose_level','bmi',
'smoking_status']
"""
# Note: 'stroke' column is not included as a feature
feature_cols = [
"gender","age","hypertension","heart_disease","ever_married",
"work_type","Residence_type","avg_glucose_level","bmi",
"smoking_status"
]
df = pd.DataFrame([{k: data[k] for k in feature_cols}])
return df
def predict_stroke(model, X: pd.DataFrame):
"""
Returns human-readable label and probability for the top class.
"""
proba = model.predict_proba(X)[0]
idx = proba.argmax()
label_map = {0: "No Stroke", 1: "Stroke"}
return label_map[idx], proba[idx]