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.0.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.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamic_genetic_algo-2.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 4e6af2fdabc8e0b778d348392f91d907f49325347995173c7dcf38f34e74764a
MD5 71405479c641fa9ecb3f8f7de47e0ab6
BLAKE2b-256 733c45a876d3dfd5666066bdb22a2d2f365021e6e0f0424ad1ee3055f07825a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dynamic_genetic_algo-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ef56f4d445fd23743b56a5679a1328f01910f1cfddc164e65c8ae739918ba87
MD5 c364a8f0e55b3fdbad7c2e85d9bc3c1f
BLAKE2b-256 dc08e339d2cf1e7b63bc43d9a1a3cfbe2e97ffaab5b0f7db75be7a9c55524d9c

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