Skip to main content

A genetic algorithm library

Project description

Genetic Algorithm for Flexible Data Handling

A Python library that leverages genetic algorithms to generate optimized queries for handling data flexibly without dropping rows. This approach enables selective row exclusion per query, bypassing the need for imputation or deletion, and supports high-volume data processing through parallelism.

Features

  • Generates custom queries to ignore specific rows based on query-specific criteria.
  • Supports high-volume data processing with parallel computation.
  • Dynamically calculates feature-specific min/max values for optimized filtering.
  • Enables binary classification filtering and calculates the percentage of 1s.

Workflow

  1. Load and Clean Data:

    • Load data and apply minimal cleaning (e.g., drop inf values or other outliers that could disrupt quintile calculations).
  2. Set Parameters:

    • Define parameters that control the algorithm's behavior and query generation.
  3. Dynamic Feature Computation:

    • Compute min/max values and deltas dynamically for each feature to enhance query specificity.
  4. Generate Feature-Specific Combinations:

    • Produce min/max combinations for each feature based on unique criteria.
  5. Filter Data:

    • Filter CSVs using generated criteria, calculating the percentage of 1s for binary classification tasks (if applicable).
  6. Genetic Algorithm Optimization:

    • Carry over the fittest combinations to the next generation, introducing new entries at a defined rate for continuous improvement.

Installation

Install the package via pip:

pip install dynamic_genetic_algo

from dynamic_genetic_algo import GeneticAlgorithm, GeneticParams

# Define the genetic parameters
genetic_params = GeneticParams(
    population_size=200,
    elite_size=0.1,
    mutation_rate=0.6,
    generations=1000,
    min_size_ratio=0.005,  # Percent of dataset that must be retained to avoid anomalies
    average_column="Example Target",
    categorical_columns=id_dict,  # Dictionary where key is column name and value is list of possible categories
    super_elite=20  # Extra privileges for the top elite
)

# Initialize and run the genetic algorithm
if __name__ == "__main__":
    genetic_algo = GeneticAlgorithm(
        training_data=combined_df,
        target="Target Over 5",
        columns_to_drop=[
            "Sample Column 1",
            "Sample Column 2",
            "Target"  # Exclude target column from queries
        ],
        genetic_params=genetic_params,
    )
    genetic_algo.run()

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

dynamic_genetic_algo-2.0.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamic_genetic_algo-2.0.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file dynamic_genetic_algo-2.0.1.tar.gz.

File metadata

  • Download URL: dynamic_genetic_algo-2.0.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for dynamic_genetic_algo-2.0.1.tar.gz
Algorithm Hash digest
SHA256 8cebc8e2d8899d55031563f8b2dbede33f669c523d00605bb80e224f5de220a5
MD5 ce3f132ed09f3397748445bc162bf22f
BLAKE2b-256 0362e35ce5b420e891b9ac4823cd15a6a767baa2ccf7797fbcfe8b13d08ad6b1

See more details on using hashes here.

File details

Details for the file dynamic_genetic_algo-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dynamic_genetic_algo-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d0203f96b0deb2ed46c0dd38411d2293ce71821e3bcb9600465bebe5e8b1e784
MD5 b522e6da1c72d9a1f0213d3808f77442
BLAKE2b-256 ac7be1837aa177e29200f0fb1c870c26544e0c3c81f9d24bdcfaa4131d18feb0

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