Skip to content

giodesi/Logistic_Regression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logistic Regression Analysis Project

Project Overview

This project provides a comprehensive implementation of logistic regression analysis through both a Jupyter notebook for educational exploration and a production-ready web application. The project demonstrates the complete workflow of building, training, evaluating, and deploying binary classification models, which predict a categorical outcome (e.g., Yes/No, 1/0, Churn/Stay) based on one or more independent variables.

The implementation focuses on accessibility and generalization, enabling users to apply logistic regression techniques to their own data without requiring extensive programming knowledge. The project maintains statistical rigor while presenting complex concepts like feature importance and model performance through intuitive visualizations and clear, understandable metrics.

Project Resources

The complete implementation includes both educational materials and production-ready code.

  • Logistic_Regression.ipynb: A comprehensive Jupyter notebook providing a step-by-step walkthrough of logistic regression concepts. It covers data loading (ChurnData.csv), preprocessing (feature selection, scaling), model training, and evaluation using log_loss.
  • app.py: The source code for the interactive Streamlit web application, allowing users to upload their own data, train a model, and make predictions.
  • requirements.txt: A list of all necessary Python libraries to run the project.
  • ChurnData.csv: The sample dataset used in the notebook and as a demo for the app, containing hypothetical customer data for predicting churn.

Core Features of the Web Application (app.py)

  • Data Upload & Validation: Allows users to upload their own CSV files for training or prediction. The app validates columns and checks for missing data.
  • Feature & Target Selection: An intuitive interface to select which columns to use as independent variables (X) and which single column to use as the binary target variable (y).
  • Model Configuration: Easy-to-use controls for splitting data (Test Set Size), ensuring reproducibility (Random State), and applying feature scaling (Standardization).
  • Model Training: One-click training of a scikit-learn Logistic Regression model on the user's data.
  • Model Evaluation: Comprehensive performance metrics are generated instantly, including Accuracy, Log Loss, a Confusion Matrix, and a full Classification Report (Precision, Recall, F1-Score).
  • Prediction Mode: Users can switch to prediction mode to upload new, unseen data and get classifications from the already-trained model.
  • Interactive Visualizations:
    • Bar charts showing Feature Coefficients to understand variable importance.
    • Heatmaps for the Confusion Matrix to visualize prediction accuracy.
    • Histograms for Prediction Probabilities to see model confidence.
  • Data Export: Download model coefficients and full prediction results (with probabilities) as a CSV file.

Technical Implementation

  • Libraries: The project is built using standard data science and web app libraries, including:
    • Streamlit: For creating the interactive web application interface.
    • Pandas: For data manipulation and loading CSV files.
    • Scikit-learn (sklearn): For model training (LogisticRegression), preprocessing (StandardScaler, train_test_split), and evaluation (accuracy_score, log_loss, confusion_matrix, classification_report).
    • Matplotlib & Seaborn: For generating static visualizations like the coefficient plot and confusion matrix.
  • Workflow:
    1. Load Data: The app loads a user-provided CSV into a Pandas DataFrame.
    2. Preprocess: The user selects features and a target. The app separates the data, applies StandardScaler (if checked), and splits it into training and testing sets.
    3. Train Model: A LogisticRegression model is instantiated and fit on the training data.
    4. Evaluate: The trained model makes predictions and predicts probabilities on the test set. These are used to calculate all performance metrics and generate visualizations.
    5. Predict: In prediction mode, the saved model and scaler are used to transform and predict new, unseen data.

Usage Instructions

  1. Install Dependencies:

    pip install -r requirements.txt
  2. Run the Application:

    streamlit run app.py
  3. Train a Model:

    • Select 'Training Data' in the sidebar.
    • Upload your CSV file (or use ChurnData.csv as an example).
    • Select your features (e.g., tenure, age, income) and your binary target variable (e.g., churn).
    • Click 'Train Model'.
    • Explore the results in the tabs.
  4. Make Predictions:

    • After training a model, select 'New Data for Prediction' in the sidebar.
    • Upload a new CSV file that contains the same features used for training.
    • Click 'Make Predictions'.
    • View and download the results.
  5. Reset:

    • Click the 'Reset Application' button at any time to clear the model and data and start over.

License

This project is licensed under the MIT License - see the LICENSE file for details. This permissive license allows for commercial use, modification, distribution, and private use.

Attribution & Data

The ChurnData.csv dataset used in the notebook is a hypothetical customer dataset from a telecommunications company, designed to predict customer churn. It serves as a classic, real-world example for binary classification tasks.

Support and Documentation

For optimal results, users should ensure their target variable is binary (0/1). The application provides informative error messages for common issues (e.g., missing columns, non-numeric data) and includes contextual guidance throughout the interface to support users.

About

Interactive logistic regression toolkit featuring a Jupyter notebook for educational exploration and a Streamlit web application for real-time analysis. Upload any CSV dataset to train, evaluate, and visualize regression models with comprehensive metrics and residual diagnostics. Perfect for learning ML fundamentals and data analysis

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors