Skip to main content

Biblioteca para otimização de hiperparâmetros do XGBoost usando algoritmos genéticos.

Project description

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 🌟

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:

    pip3 install xgboost_genetic
    

Usage 🧑‍💻

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

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:

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:
    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 file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xgboost_genetic-0.0.3.tar.gz (14.2 kB view details)

Uploaded Source

File details

Details for the file xgboost_genetic-0.0.3.tar.gz.

File metadata

  • Download URL: xgboost_genetic-0.0.3.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for xgboost_genetic-0.0.3.tar.gz
Algorithm Hash digest
SHA256 850a1411d8d269325bd999bd635214f73916afd4b553ffcee568376016037a06
MD5 72d17e195ff567a2376400448b5e0a86
BLAKE2b-256 47d8df72f3bf7fdfbedaf428b93e00218b6463d464ce953e4ef9d0f5d7018267

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page