# danielverdidoamarante/churn architecture

> Architecture diagram of the GitHub repository danielverdidoamarante/churn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/danielverdidoamarante/churn
- Repository: https://github.com/danielverdidoamarante/churn

## Overview

##### Main Components
- Data Input: Represent the "data" directory as the source of raw CSV files (e.g., Abandono_clientes.csv for training and Abandono_teste.csv for predictions).
- Exploratory Data Analysis (EDA): Represent the "EDA.ipynb" notebook which performs initial data exploration, visualizations, and descriptive statistics.
- Data Preprocessing: Show the "preprocess.py" component that handles data cleaning and transformation (such as detecting CSV delimiters and converting categorical variables).
- Model Training: Include both "train_models.py" and "train.py" which are responsible for training various models (with the Random Forest algorithm highlighted) and saving the trained model.
- Prediction: Illustrate "predict.py" that loads the saved model, runs predictions on new data, and writes results.
- Output Generation: Represent the "output" directory where the prediction results (CSV file) are saved.

##### Relationships and Interactions
- The output of Preprocessing is then fed into the Model Training component.
- Post training, the trained model is saved to the Model Storage area.
- For generating new predictions, the Prediction component reads both the new data (from the Data directory) and the saved model, ultimately outputting predictions to the Output directory.

##### Architectural Patterns & Design Principles
- Pipeline Architecture: A sequential flow from data ingestion to preprocessing to training to inference.
- Separation of Concerns: Each component (EDA, preprocessing, training, prediction) serves a distinct role.
- Modularity: Components such as preprocessing and model training can be developed, tested, and maintained independently.
- Use of dependency injection is implicit – for example, prediction scripts rely on models saved via joblib; reusing components (like preprocessing methods) can be indicated if needed.

##### Technologies, Frameworks, and Libraries
- pandas: For data manipulation in both preprocessing and EDA.
- scikit-learn: For machine learning model training (Random Forest and potentially other classifiers in train_models.py).
- joblib: For saving and loading the trained models stored in the models directory.
- matplotlib and seaborn: For data visualization in the EDA.ipynb notebook.
- Python scripts: All critical sections are implemented as Python scripts, emphasizing a scripting-based data science workflow.

## Diagram (Mermaid)

```mermaid
graph TD
    DataInput["Data Input (data)"]:::storage
    EDA["Exploratory Data Analysis (EDA.ipynb)"]:::notebook
    Preprocess["Data Preprocessing (preprocess.py)"]:::script

    subgraph "Model Training"
        TrainModels["Train Models (train_models.py)"]:::script
        Train["Train Script (train.py)"]:::script
    end

    ModelStorage["Model Storage (models)"]:::storage
    Prediction["Prediction (predict.py)"]:::script
    Output["Output Generation (output)"]:::storage

    DataInput -->|"rawToEDA"| EDA
    DataInput -->|"rawToPreproc"| Preprocess
    Preprocess -->|"toTrain"| TrainModels
    Preprocess -->|"toTrain"| Train
    TrainModels -->|"savesModel"| ModelStorage
    Train -->|"savesModel"| ModelStorage
    DataInput -->|"testData"| Prediction
    ModelStorage -->|"model"| Prediction
    Prediction -->|"writesResult"| Output

    click DataInput "https://github.com/danielverdidoamarante/churn/tree/main/data/"
    click EDA "https://github.com/danielverdidoamarante/churn/blob/main/EDA.ipynb"
    click Preprocess "https://github.com/danielverdidoamarante/churn/blob/main/preprocess.py"
    click TrainModels "https://github.com/danielverdidoamarante/churn/blob/main/train_models.py"
    click Train "https://github.com/danielverdidoamarante/churn/blob/main/train.py"
    click ModelStorage "https://github.com/danielverdidoamarante/churn/tree/main/models/"
    click Prediction "https://github.com/danielverdidoamarante/churn/blob/main/predict.py"
    click Output "https://github.com/danielverdidoamarante/churn/tree/main/output/"

    classDef storage fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef script fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef notebook fill:#d5e8d4,stroke:#333,stroke-width:2px;
```
