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-1.0.1.tar.gz (6.1 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-1.0.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamic_genetic_algo-1.0.1.tar.gz
  • Upload date:
  • Size: 6.1 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-1.0.1.tar.gz
Algorithm Hash digest
SHA256 355f793c38f43d5e9aa57105c47d59a88d2264a7e67baa11378db1680c2459a2
MD5 6af449a78fb79ec3060ef85b86d9cc1a
BLAKE2b-256 5468d967a3270da9b2820196ef20d03baa3a4f2e4ad26bddd9ef8e528cddc761

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dynamic_genetic_algo-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 95ae1826e7a0b69f41814b6d27106c85da990ce4dd6b4221fb956cc9f8f34df9
MD5 834bacfab9394b43a05e5723c590a4d2
BLAKE2b-256 b661442c64fbf057c110ebfc653fe5f32c8c2ecb1ecc8bc5d92a4a00d3a14491

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