LatentBoostClassifier


NameLatentBoostClassifier JSON
Version 1.2.4 PyPI version JSON
download
home_pagehttps://github.com/AliBavarchee/LatentBoostClassifier
SummaryA hybrid generative model combining CVAE, CGAN, and Random Forest.
upload_time2025-02-22 16:11:12
maintainerNone
docs_urlNone
authorAli Bavarchee
requires_python>=3.7
licenseMIT
keywords machine learning generative models cvae cgan random forest
VCS
bugtrack_url
requirements requirements.txt
Travis-CI No Travis.
coveralls test coverage No coveralls.
            __________________________________________________<p align="Center">![logo](https://teal-broad-gecko-650.mypinata.cloud/ipfs/bafybeidgioyzbiwfsdbnpkxvpjtppn3zd275ryjzi77izbrjo4lr4on3za)</p>__________________________________________________
---
__     ___  ______  ____ __  __ ______
       ||    // \\ | || | ||    ||\ || | || |
       ||    ||=||   ||   ||==  ||\\||   ||  
       ||__| || ||   ||   ||___ || \||   ||    
	   ____    ___     ___    __  ______
          || ))  // \\   // \\  (( \ | || |
          ||=)  ((   )) ((   ))  \\    ||  
          ||_))  \\_//   \\_//  \_))   ||
  	        __                         
           /   |  _   _  _ . (_ .  _  _ 
           \__ | (_| _) _) | |  | (- |
             __       ___           
            /_ |     |__ \      |    | 
             | |        ) |     |    | 
             | |       / /      |    |  
             | |  __  / /_   __ |____|__
             |_| (__)|____| (__)     |
---
---
# LatentBoostClassifier: Hybrid Generative Model: CVAE + CGAN + RF
---
---
| http://dx.doi.org/10.13140/RG.2.2.11351.79522 |
---

This repository implements a **hybrid generative model+** combining a Conditional Variational Autoencoder (CVAE), a Conditional Generative Adversarial Network (CGAN), and a Random Forest Classifier (RFC). The hybrid model is designed for complex classification tasks by leveraging latent feature extraction (CVAE), synthetic data generation (CGAN), and robust classification (RFC).

---

## Features

1. **Conditional Variational Autoencoder (CVAE)**:
   - Learns a latent representation of input data.
   - Uses a custom loss function combining reconstruction loss and KL divergence.

2. **Conditional Generative Adversarial Network (CGAN)**:
   - Generates high-quality synthetic data conditioned on class labels.

3. **Random Forest Classifier**:
   - Trained on a combination of real and synthetic features to enhance classification performance.

4. **Parallel Model Training**:
   - The CVAE and CGAN models are trained concurrently using Python's `multiprocessing` module.

5. **Hyperparameter Tuning**:
   - Utilizes **Keras Tuner** for optimizing the CVAE and CGAN hyperparameters.
   - Random Forest is tuned using **GridSearchCV**.

---

## Installation

### Prerequisites
- Python 3.7+
- TensorFlow 2.8+
- Scikit-learn
- Keras Tuner
- Matplotlib
- Seaborn
- Multiprocessing

### Install Required Packages
```bash
pip install tensorflow keras-tuner scikit-learn matplotlib seaborn
```

---

---

**Install the Package**

the package can be installed the package via PyPI:
```bash
pip install LatentBoostClassifier
```

Alternatively, install directly from GitHub:
```bash
pip install git+https://github.com/AliBavarchee/LatentBoostClassifier.git
```

---


## Usage

---

### Using the Package

After installation, the package can be imported and used like this:
```python
from LatentBoostClassifier import parallel_train, visualize_hybrid_model

# Train the hybrid model
best_cvae, best_cgan_generator, best_rf_model = parallel_train(X_train, Y_train, X_test, Y_test)

# Visualize results
visualize_hybrid_model(best_cvae, best_cgan_generator, best_rf_model, X_test, Y_test, X_train, Y_train)
```

---

### Training the Hybrid Model
Train the CVAE, CGAN, and Random Forest models using your dataset:
```python
# Import the training function
from LatentBoostClassifier import parallel_train

# Define training and testing datasets
X_train, Y_train = ...  # Load or preprocess your training data
X_test, Y_test = ...    # Load or preprocess your test data

# Train the hybrid model
best_cvae, best_cgan_generator, best_rf_model = parallel_train(X_train, Y_train, X_test, Y_test)
```

---

### Visualizing Results
Evaluate and visualize the performance of the hybrid model:
```python
from LatentBoostClassifier import visualize_hybrid_model

# Visualize results
visualize_hybrid_model(best_cvae, best_cgan_generator, best_rf_model, X_test, Y_test, X_train, Y_train)
```

---

## Code Overview

### 1. CVAE
- **Purpose**: Extract latent features from input data.
- **Key Components**:
  - Custom loss function: Combines reconstruction loss and KL divergence.
  - Encoder-Decoder architecture.
- **Hyperparameter Tuning**:
  - Latent dimensions.
  - Dense layer units.
  - Learning rate.

### 2. CGAN
- **Purpose**: Generate synthetic data conditioned on class labels.
- **Key Components**:
  - Generator: Produces synthetic samples.
  - Discriminator: Distinguishes real and synthetic samples.
- **Hyperparameter Tuning**:
  - Latent dimensions.
  - Dense layer units.
  - Learning rate.

### 3. Random Forest
- **Purpose**: Classify combined real and synthetic data.
- **Key Components**:
  - Trained on latent features (CVAE) and synthetic data (CGAN).
  - Grid search for hyperparameter optimization.

---

## Visualization

### Classification Performance
- **Confusion Matrix**:
  Visualize actual vs. predicted class distributions.
- **Classification Report**:
  Display precision, recall, F1-score, and accuracy metrics.

### Latent Space
- Use **t-SNE** to visualize the CVAE's latent space.

### Synthetic Data
- Compare real and synthetic data distributions using KDE plots.

### ROC Curve
- Evaluate the Random Forest classifier with an ROC curve and compute AUC.

---

## Key Functions

### Model Training
```python
parallel_train(X_train, Y_train, X_test, Y_test)
```
- Trains the CVAE, CGAN, and Random Forest models in parallel.

### Visualization
```python
visualize_hybrid_model(best_cvae, best_cgan_generator, best_rf_model, X_test, Y_test, X_train, Y_train)
```
- Visualizes the hybrid model's results, including latent space and classification performance.

---

## Examples

### Training Example
```python
# Example Dataset
X_train = np.random.rand(80, 10)
Y_train = np.random.randint(0, 2, size=(80, 1))
X_test = np.random.rand(20, 10)
Y_test = np.random.randint(0, 2, size=(20, 1))

# Train the hybrid model
best_cvae, best_cgan_generator, best_rf_model = parallel_train(X_train, Y_train, X_test, Y_test)
```

### Visualization Example
```python
# Visualize results
visualize_hybrid_model(best_cvae, best_cgan_generator, best_rf_model, X_test, Y_test, X_train, Y_train)
```

---

## Contributions

Feel free to fork, improve, and submit a pull request! For major changes, please open an issue first to discuss what you'd like to change.

---

## License

This project is licensed under the MIT License. See the `LICENSE` file for details.
---

=============================================<p align="Center">![ALI BAVARCHIEE](https://teal-broad-gecko-650.mypinata.cloud/ipfs/bafkreif332ra4lrdjfzaiowc2ikhl65uflok37e7hmuxomwpccracarqpy)</p>=============================================
=====
| https://github.com/AliBavarchee/ |
----
| https://www.linkedin.com/in/ali-bavarchee-qip/ |
----

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AliBavarchee/LatentBoostClassifier",
    "name": "LatentBoostClassifier",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "machine learning generative models CVAE CGAN Random Forest",
    "author": "Ali Bavarchee",
    "author_email": "ali.bavarchee@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/59/17/94448f8fac41d446e72a127bce172d120f3b655094b48ab6b87643246e3c/LatentBoostClassifier-1.2.4.tar.gz",
    "platform": null,
    "description": "__________________________________________________<p align=\"Center\">![logo](https://teal-broad-gecko-650.mypinata.cloud/ipfs/bafybeidgioyzbiwfsdbnpkxvpjtppn3zd275ryjzi77izbrjo4lr4on3za)</p>__________________________________________________\r\n---\r\n__     ___  ______  ____ __  __ ______\r\n       ||    // \\\\ | || | ||    ||\\ || | || |\r\n       ||    ||=||   ||   ||==  ||\\\\||   ||  \r\n       ||__| || ||   ||   ||___ || \\||   ||    \r\n\t   ____    ___     ___    __  ______\r\n          || ))  // \\\\   // \\\\  (( \\ | || |\r\n          ||=)  ((   )) ((   ))  \\\\    ||  \r\n          ||_))  \\\\_//   \\\\_//  \\_))   ||\r\n  \t        __                         \r\n           /   |  _   _  _ . (_ .  _  _ \r\n           \\__ | (_| _) _) | |  | (- |\r\n             __       ___           \r\n            /_ |     |__ \\      |    | \r\n             | |        ) |     |    | \r\n             | |       / /      |    |  \r\n             | |  __  / /_   __ |____|__\r\n             |_| (__)|____| (__)     |\r\n---\r\n---\r\n# LatentBoostClassifier: Hybrid Generative Model: CVAE + CGAN + RF\r\n---\r\n---\r\n| http://dx.doi.org/10.13140/RG.2.2.11351.79522 |\r\n---\r\n\r\nThis repository implements a **hybrid generative model+** combining a Conditional Variational Autoencoder (CVAE), a Conditional Generative Adversarial Network (CGAN), and a Random Forest Classifier (RFC). The hybrid model is designed for complex classification tasks by leveraging latent feature extraction (CVAE), synthetic data generation (CGAN), and robust classification (RFC).\r\n\r\n---\r\n\r\n## Features\r\n\r\n1. **Conditional Variational Autoencoder (CVAE)**:\r\n   - Learns a latent representation of input data.\r\n   - Uses a custom loss function combining reconstruction loss and KL divergence.\r\n\r\n2. **Conditional Generative Adversarial Network (CGAN)**:\r\n   - Generates high-quality synthetic data conditioned on class labels.\r\n\r\n3. **Random Forest Classifier**:\r\n   - Trained on a combination of real and synthetic features to enhance classification performance.\r\n\r\n4. **Parallel Model Training**:\r\n   - The CVAE and CGAN models are trained concurrently using Python's `multiprocessing` module.\r\n\r\n5. **Hyperparameter Tuning**:\r\n   - Utilizes **Keras Tuner** for optimizing the CVAE and CGAN hyperparameters.\r\n   - Random Forest is tuned using **GridSearchCV**.\r\n\r\n---\r\n\r\n## Installation\r\n\r\n### Prerequisites\r\n- Python 3.7+\r\n- TensorFlow 2.8+\r\n- Scikit-learn\r\n- Keras Tuner\r\n- Matplotlib\r\n- Seaborn\r\n- Multiprocessing\r\n\r\n### Install Required Packages\r\n```bash\r\npip install tensorflow keras-tuner scikit-learn matplotlib seaborn\r\n```\r\n\r\n---\r\n\r\n---\r\n\r\n**Install the Package**\r\n\r\nthe package can be installed the package via PyPI:\r\n```bash\r\npip install LatentBoostClassifier\r\n```\r\n\r\nAlternatively, install directly from GitHub:\r\n```bash\r\npip install git+https://github.com/AliBavarchee/LatentBoostClassifier.git\r\n```\r\n\r\n---\r\n\r\n\r\n## Usage\r\n\r\n---\r\n\r\n### Using the Package\r\n\r\nAfter installation, the package can be imported and used like this:\r\n```python\r\nfrom LatentBoostClassifier import parallel_train, visualize_hybrid_model\r\n\r\n# Train the hybrid model\r\nbest_cvae, best_cgan_generator, best_rf_model = parallel_train(X_train, Y_train, X_test, Y_test)\r\n\r\n# Visualize results\r\nvisualize_hybrid_model(best_cvae, best_cgan_generator, best_rf_model, X_test, Y_test, X_train, Y_train)\r\n```\r\n\r\n---\r\n\r\n### Training the Hybrid Model\r\nTrain the CVAE, CGAN, and Random Forest models using your dataset:\r\n```python\r\n# Import the training function\r\nfrom LatentBoostClassifier import parallel_train\r\n\r\n# Define training and testing datasets\r\nX_train, Y_train = ...  # Load or preprocess your training data\r\nX_test, Y_test = ...    # Load or preprocess your test data\r\n\r\n# Train the hybrid model\r\nbest_cvae, best_cgan_generator, best_rf_model = parallel_train(X_train, Y_train, X_test, Y_test)\r\n```\r\n\r\n---\r\n\r\n### Visualizing Results\r\nEvaluate and visualize the performance of the hybrid model:\r\n```python\r\nfrom LatentBoostClassifier import visualize_hybrid_model\r\n\r\n# Visualize results\r\nvisualize_hybrid_model(best_cvae, best_cgan_generator, best_rf_model, X_test, Y_test, X_train, Y_train)\r\n```\r\n\r\n---\r\n\r\n## Code Overview\r\n\r\n### 1. CVAE\r\n- **Purpose**: Extract latent features from input data.\r\n- **Key Components**:\r\n  - Custom loss function: Combines reconstruction loss and KL divergence.\r\n  - Encoder-Decoder architecture.\r\n- **Hyperparameter Tuning**:\r\n  - Latent dimensions.\r\n  - Dense layer units.\r\n  - Learning rate.\r\n\r\n### 2. CGAN\r\n- **Purpose**: Generate synthetic data conditioned on class labels.\r\n- **Key Components**:\r\n  - Generator: Produces synthetic samples.\r\n  - Discriminator: Distinguishes real and synthetic samples.\r\n- **Hyperparameter Tuning**:\r\n  - Latent dimensions.\r\n  - Dense layer units.\r\n  - Learning rate.\r\n\r\n### 3. Random Forest\r\n- **Purpose**: Classify combined real and synthetic data.\r\n- **Key Components**:\r\n  - Trained on latent features (CVAE) and synthetic data (CGAN).\r\n  - Grid search for hyperparameter optimization.\r\n\r\n---\r\n\r\n## Visualization\r\n\r\n### Classification Performance\r\n- **Confusion Matrix**:\r\n  Visualize actual vs. predicted class distributions.\r\n- **Classification Report**:\r\n  Display precision, recall, F1-score, and accuracy metrics.\r\n\r\n### Latent Space\r\n- Use **t-SNE** to visualize the CVAE's latent space.\r\n\r\n### Synthetic Data\r\n- Compare real and synthetic data distributions using KDE plots.\r\n\r\n### ROC Curve\r\n- Evaluate the Random Forest classifier with an ROC curve and compute AUC.\r\n\r\n---\r\n\r\n## Key Functions\r\n\r\n### Model Training\r\n```python\r\nparallel_train(X_train, Y_train, X_test, Y_test)\r\n```\r\n- Trains the CVAE, CGAN, and Random Forest models in parallel.\r\n\r\n### Visualization\r\n```python\r\nvisualize_hybrid_model(best_cvae, best_cgan_generator, best_rf_model, X_test, Y_test, X_train, Y_train)\r\n```\r\n- Visualizes the hybrid model's results, including latent space and classification performance.\r\n\r\n---\r\n\r\n## Examples\r\n\r\n### Training Example\r\n```python\r\n# Example Dataset\r\nX_train = np.random.rand(80, 10)\r\nY_train = np.random.randint(0, 2, size=(80, 1))\r\nX_test = np.random.rand(20, 10)\r\nY_test = np.random.randint(0, 2, size=(20, 1))\r\n\r\n# Train the hybrid model\r\nbest_cvae, best_cgan_generator, best_rf_model = parallel_train(X_train, Y_train, X_test, Y_test)\r\n```\r\n\r\n### Visualization Example\r\n```python\r\n# Visualize results\r\nvisualize_hybrid_model(best_cvae, best_cgan_generator, best_rf_model, X_test, Y_test, X_train, Y_train)\r\n```\r\n\r\n---\r\n\r\n## Contributions\r\n\r\nFeel free to fork, improve, and submit a pull request! For major changes, please open an issue first to discuss what you'd like to change.\r\n\r\n---\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\r\n---\r\n\r\n=============================================<p align=\"Center\">![ALI BAVARCHIEE](https://teal-broad-gecko-650.mypinata.cloud/ipfs/bafkreif332ra4lrdjfzaiowc2ikhl65uflok37e7hmuxomwpccracarqpy)</p>=============================================\r\n=====\r\n| https://github.com/AliBavarchee/ |\r\n----\r\n| https://www.linkedin.com/in/ali-bavarchee-qip/ |\r\n----\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A hybrid generative model combining CVAE, CGAN, and Random Forest.",
    "version": "1.2.4",
    "project_urls": {
        "Documentation": "https://github.com/AliBavarchee/LatentBoostClassifier#readme",
        "Homepage": "https://github.com/AliBavarchee/LatentBoostClassifier",
        "Source": "https://github.com/AliBavarchee/LatentBoostClassifier",
        "Tracker": "https://github.com/AliBavarchee/LatentBoostClassifier/issues"
    },
    "split_keywords": [
        "machine",
        "learning",
        "generative",
        "models",
        "cvae",
        "cgan",
        "random",
        "forest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "25bd782030846cb462758f0ec2898569d93dc073641319f6d13e4803caa9adc9",
                "md5": "a8c7faa42967fb3966ed4cfc2e02d404",
                "sha256": "75f011138ce3ad50182069341b15fbae55fbfdd86b9043ec2109365bb9d0fda3"
            },
            "downloads": -1,
            "filename": "LatentBoostClassifier-1.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a8c7faa42967fb3966ed4cfc2e02d404",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 409893,
            "upload_time": "2025-02-22T16:11:00",
            "upload_time_iso_8601": "2025-02-22T16:11:00.276891Z",
            "url": "https://files.pythonhosted.org/packages/25/bd/782030846cb462758f0ec2898569d93dc073641319f6d13e4803caa9adc9/LatentBoostClassifier-1.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "591794448f8fac41d446e72a127bce172d120f3b655094b48ab6b87643246e3c",
                "md5": "541880832eb8d6b7ecf338e3382db604",
                "sha256": "1be6a478f5bad17cb5b50fda9f6b8b3fc9f164c3770d698a325274eaa8bd68f7"
            },
            "downloads": -1,
            "filename": "LatentBoostClassifier-1.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "541880832eb8d6b7ecf338e3382db604",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 413194,
            "upload_time": "2025-02-22T16:11:12",
            "upload_time_iso_8601": "2025-02-22T16:11:12.309083Z",
            "url": "https://files.pythonhosted.org/packages/59/17/94448f8fac41d446e72a127bce172d120f3b655094b48ab6b87643246e3c/LatentBoostClassifier-1.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-22 16:11:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AliBavarchee",
    "github_project": "LatentBoostClassifier",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "requirements.txt",
            "specs": []
        }
    ],
    "lcname": "latentboostclassifier"
}
        
Elapsed time: 0.51848s