End-to-end machine learning project with logistic regression to predict customer churn, using FastAPI for the backend and Streamlit for a modern, interactive frontend.
This project predicts the likelihood of customer churn (service cancellation) for a telecommunications company. Using customer service, billing, and demographic data, it estimates whether a customer is at high risk of leaving.
- Cleaned dataset with over 7,000 customers
- More than 30 input features
- Integrated machine learning + API + frontend interface
- Feature selection and cleaning
- One-hot encoding for categorical variables
- Standardization of numerical features
- Logistic Regression training
- Model evaluation (Confusion Matrix, Accuracy, Precision, AUC)
- Model serialization with
pickle
The model is served using a FastAPI backend for real-time predictions.
-
Install dependencies:
pip install fastapi uvicorn scikit-learn pandas numpy
-
Run the API:
uvicorn fastAPI.main:app --reload
-
Access the Swagger docs at:
- POST
/predict- Input: JSON with customer attributes
- Output: Churn probability and prediction (0 = no churn, 1 = churn)
{
"Contract": 0,
"Tech_Support": 1,
"Tenure_Months": 10,
"Online_Security": 2,
"Internet_Service": 1,
"Device_Protection": 0,
"Payment_Method": 2,
"Monthly_Charges": 85.90,
"Online_Backup": 0,
"Dependents": 0,
"Streaming_TV": 1,
"Streaming_Movies": 1
}{
"churn_probability": 0.742,
"prediction": 1
}An interactive frontend built with Streamlit allows users to input customer data and view real-time predictions in an intuitive and styled interface.
-
Install dependencies:
pip install streamlit requests
-
Launch the app:
streamlit run fastAPI\app.py
- User-friendly input forms with radio buttons, sliders, and dropdowns
- Clean two-column layout for better organization
- Real-time API communication
- Styled result output with probability, colors, and risk icons (🟢 / 🔴)
- Error handling and loading animations

Note
The code descriptions are in Portuguese 🇧🇷, although the variables and code are in English.
# Author Info
# LinkedIn: https://www.linkedin.com/in/profile-mariana-martins/
# GitHub: https://github.com/marianamartiyns
# Email: marianamartiyns@gmail.com