Instructions to use rajistics/churn-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use rajistics/churn-model with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("rajistics/churn-model", "churn.pkl") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Download handler.py from rajistics/churn-model: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/rajistics/churn-model/resolve/main/handler.py
- Command line
-
hf download hf://rajistics/churn-model/handler.py
-
curl -L -o handler.py https://huggingface.co/rajistics/churn-model/resolve/main/handler.py
1.06 kB
| import pandas as pd | |
| import pickle | |
| from typing import Dict, List, Any | |
| import numpy as np | |
| import os | |
| # set device | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| # load the optimized model | |
| pathb = os.path.join(path,"./churn.pkl") | |
| self.pipe = pd.read_pickle(pathb) | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| """ | |
| Args: | |
| data (:obj:): | |
| includes the input data and the parameters for the inference. | |
| Return: | |
| A :obj:`list`:. A string representing what the label/class is | |
| """ | |
| inputs = data.pop("inputs", data) | |
| parameters = data.pop("parameters", None) | |
| df = pd.DataFrame(inputs) | |
| df["TotalCharges"] = df["TotalCharges"].replace(" ", np.nan, regex=False).astype(float) | |
| df = df.drop(columns=["customerID"]) | |
| df = df.drop(columns=["Churn"]) | |
| # run inference pipeline | |
| pred = self.pipe.predict(df) | |
| # postprocess the prediction | |
| return {"pred": pred} | |