Metadata-Version: 2.1
Name: xgboost_genetic
Version: 0.0.3
Summary: Biblioteca para otimização de hiperparâmetros do XGBoost usando algoritmos genéticos.
Home-page: https://github.com/PauloDoMonte/xgboost_genetic
Author: Paulo Do Monte
Author-email: paulo.monte.fis@gmail.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE

# XGBoost Genetic Algorithm 🧬 + 📊

This project combines the power of **XGBoost** and **Genetic Algorithms** to optimize hyperparameters for machine learning models. By using a genetic approach, we can efficiently search for the best-performing set of hyperparameters for XGBoost, improving model performance and reducing manual hyperparameter tuning time.

## Table of Contents 📑

- [Introduction](#introduction)
- [Features](#features)
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Usage](#usage)
- [Example](#example)
- [Contributing](#contributing)
- [License](#license)

## Introduction 🌟

Hyperparameter tuning is often a time-consuming task in machine learning. While techniques like grid search or random search are common, they can be computationally expensive. This repository introduces a novel approach using **genetic algorithms** to optimize **XGBoost** hyperparameters. The algorithm mimics the process of natural selection to find the best hyperparameters more efficiently.

By evolving a population of candidate solutions, this method automatically adjusts the parameters to improve the XGBoost model's accuracy, speed, and overall performance.

## Features 🚀

- **Genetic Algorithm** to optimize hyperparameters for XGBoost.
- Efficient search for optimal configurations using crossover, mutation, and selection.
- Easily extensible and configurable for different datasets and tasks.
- Compatible with any dataset where XGBoost is applicable.

## Getting Started 🛠️

To get started with `xgboost_genetic`, follow the instructions below to install and run the project.

### Prerequisites

Make sure you have the following installed:
- Python 3.6+
- pip (Python package installer)

### Installation 📦

1. Install from PyPi:

    ```bash
    pip3 install xgboost_genetic
    ```

## Usage 🧑‍💻

Once installed, you can run the genetic algorithm for hyperparameter optimization. Here's an example usage:

```python
import pandas as pd
from xgboost_genetic import run_pipeline, predict

# Caminho para o dataset e a coluna alvo
dataset_path = "dataset.csv"  # Substitua pelo caminho do seu dataset
target_column = "target"  # Substitua pelo nome da coluna alvo

# Executar o pipeline de treinamento e otimização
run_pipeline(dataset_path, target_column)

# Carregar o modelo treinado
model_path = "model_best_train.pkl"

# Dados de entrada para previsão
input_data = pd.DataFrame({
    "feature1": [1, 2],
    "feature2": [3, 4]
})

# Fazer previsões
predictions = predict(model_path, input_data)

# Exibir as previsões
print(predictions)
```

## Example 📈

Here's an example of how to train a new XGBoost model from scratch, optimize its hyperparameters using the genetic algorithm, and save the results:

```python
from xgboost_genetic import run_pipeline

# Caminho para o dataset e a coluna alvo
dataset_path = "path/to/dataset.csv"  # Substitua pelo caminho do seu dataset
target_column = "target"  # Substitua pelo nome da coluna alvo

# Executar o pipeline de treinamento e otimização
run_pipeline(dataset_path, target_column)

# O modelo treinado e otimizado será salvo como 'model_best_train.pkl'
# Os resultados da otimização serão salvos como 'optimization_results.pkl'
```

### Passos:
1. **Prepare o dataset**: Crie um arquivo CSV com os dados que você deseja usar para treinar o modelo.
2. **Execute o script**: Substitua `path/to/dataset.csv` pelo caminho do seu dataset e `target` pelo nome da coluna alvo no seu dataset.
3. **Execute o script**:
   ```sh
   python example_usage.py
   ```

### Explicação:
- **`run_pipeline(dataset_path, target_column)`**: Esta função carrega os dados, pré-processa, divide em treino e teste, treina um modelo inicial, otimiza os hiperparâmetros usando algoritmos genéticos e treina o modelo final com os melhores hiperparâmetros encontrados. O modelo treinado e otimizado será salvo como `model_best_train.pkl` e os resultados da otimização serão salvos como `optimization_results.pkl`.

Este exemplo demonstra como usar a biblioteca `xgboost_genetic` para treinar um novo modelo XGBoost, otimizar seus hiperparâmetros e salvar os resultados de forma simples e direta.

## Contributing 💡

We welcome contributions to make this project even better!

- Fork the repo and create your branch.
- Submit a pull request with your changes.
- Follow the coding conventions and add tests if possible.

If you have any ideas or suggestions, feel free to open an issue.

## License 📄

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.


