Instructions to use rajistics/churn-model1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use rajistics/churn-model1 with Scikit-learn:
from skops.hub_utils import download from skops.io import load download("rajistics/churn-model1", "path_to_folder") # make sure model file is in skops format # if model is a pickle file, make sure it's from a source you trust model = load("path_to_folder/churn.pkl") - Notebooks
- Google Colab
- Kaggle
| 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} |