I Built My First Machine Learning API — Here's Everything I Learned
EricMWaimiri / Telco-Customer-Churn-Prediction Customer Churn Prediction Predicts whether a telecom customer will churn using the Telco Customer Churn dataset. The project covers data cleaning and EDA, comparison of three classifiers, and a FastAPI service that serves the final model. Project Structure . ├── API/ │ └── main.py # FastAPI app serving the model ├── Data/ │ └──…
Eric MWaimiri's project, "Telco-Customer-Churn-Prediction," focuses on predicting whether a telecom customer will churn by utilizing the Telco Customer Churn dataset. The project includes data cleaning and exploratory data analysis (EDA), comparison of three classifiers, and a FastAPI service that serves the final model. The project is structured into several folders: API/ for the FastAPI app, Data/ for the raw dataset, Models/ for the fitted preprocessing and classifier pipeline and target labels, Notebooks/ for data cleaning, EDA, and model training, cpp/ (Python virtual environment), .env (environment variables), requirements.txt, and README.md.
The dataset contains 7,043 rows and 21 columns covering customer demographics, account details, and whether the customer churned or not. The main goal is to predict customer churn before it happens, similar to how Safaricom aims to identify subscribers who might switch to Airtel.
In the beginning, MWaimiri started working in a Jupyter notebook with the dataset, which includes columns such as gender, tenure, contract, monthly charges, and the churn label (Yes/No). The notebook performed data cleaning, EDA, model training, and the selection of the best model. However, a model inside a notebook is useless to others because a frontend developer cannot directly import it into an app, and a business analyst cannot simply click a button to obtain predictions.
To bridge this gap, MWaimiri created an API using FastAPI, a Python framework designed for quickly building APIs with automatic validation and interactive documentation. The project's main.py loads the fitted pipeline and target labels, which are saved as joblib files. FastAPI validates input data using Pydantic, a Python library that defines the structure of the input data.
FastAPI establishes communication between two programs over the web, following a set of agreed-upon rules. In this project, the API receives customer details and returns a prediction of whether the customer is likely to churn. Overall, MWaimiri's project demonstrates a practical application of machine learning, transforming a trained model into a useful, accessible API for various applications.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.