Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📊 Customer Churn Prediction - Multivariate Logistic Regression

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.

📋 Project Overview

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

🧪 Model Pipeline

  • 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

🚀 Backend - FastAPI

The model is served using a FastAPI backend for real-time predictions.

Running the API

  1. Install dependencies:

    pip install fastapi uvicorn scikit-learn pandas numpy
  2. Run the API:

    uvicorn fastAPI.main:app --reload
  3. Access the Swagger docs at:

API Endpoint

  • POST /predict
    • Input: JSON with customer attributes
    • Output: Churn probability and prediction (0 = no churn, 1 = churn)

Example Request:

{
  "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
}

Example Response:

{
  "churn_probability": 0.742,
  "prediction": 1
}

🎨 Frontend - Streamlit

An interactive frontend built with Streamlit allows users to input customer data and view real-time predictions in an intuitive and styled interface.

Running the App

  1. Install dependencies:

    pip install streamlit requests
  2. Launch the app:

    streamlit run fastAPI\app.py

App Features

  • 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 app

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

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages