__________________________________________________<p align="Center">![logo](HybridGenerativeModel_Slogo.png)</p>__________________________________________________
---
# LatentBoostClassifier: Hybrid Generative Model: CVAE + CGAN + RF
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 hybrid_model 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 hybrid_model 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">![logoS.png](https://github.com/AliBavarchee/AliBavarchee/blob/main/logo.png)</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/f9/2b/50029c59ce87f7a32fa9d3904784ebc84768d0c5c04650afb4a3207f0aa8/LatentBoostClassifier-1.2.3.tar.gz",
"platform": null,
"description": "__________________________________________________<p align=\"Center\">![logo](HybridGenerativeModel_Slogo.png)</p>__________________________________________________\r\n---\r\n# LatentBoostClassifier: Hybrid Generative Model: CVAE + CGAN + RF\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 hybrid_model 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 hybrid_model 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\">![logoS.png](https://github.com/AliBavarchee/AliBavarchee/blob/main/logo.png)</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.3",
"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": "78d4a300a243a37be28120f265341f6d90b0628fdefcb44309a4d065cf5d95db",
"md5": "2e92b514e44fa839f8e036607b2f0500",
"sha256": "47d95171f8a2c113e0b5146b4699ecbd7281a48ed6f6fb35944f1ffdcf6ff5e2"
},
"downloads": -1,
"filename": "LatentBoostClassifier-1.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2e92b514e44fa839f8e036607b2f0500",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 409613,
"upload_time": "2024-12-21T16:27:27",
"upload_time_iso_8601": "2024-12-21T16:27:27.595253Z",
"url": "https://files.pythonhosted.org/packages/78/d4/a300a243a37be28120f265341f6d90b0628fdefcb44309a4d065cf5d95db/LatentBoostClassifier-1.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f92b50029c59ce87f7a32fa9d3904784ebc84768d0c5c04650afb4a3207f0aa8",
"md5": "7d1d1bbb6ddc2a40df8717bc971c39aa",
"sha256": "2d76a2656dc3ba55eaf819f82082c9cbeaa176414af22eaf37fae5013af9f56c"
},
"downloads": -1,
"filename": "LatentBoostClassifier-1.2.3.tar.gz",
"has_sig": false,
"md5_digest": "7d1d1bbb6ddc2a40df8717bc971c39aa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 412820,
"upload_time": "2024-12-21T16:27:36",
"upload_time_iso_8601": "2024-12-21T16:27:36.153158Z",
"url": "https://files.pythonhosted.org/packages/f9/2b/50029c59ce87f7a32fa9d3904784ebc84768d0c5c04650afb4a3207f0aa8/LatentBoostClassifier-1.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-21 16:27:36",
"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"
}