Skip to main content

Feature Selection via Genetic Algorithm (FSGA)

PyPI version Total Downloads PyPI - Downloads

A university project implementing feature selection using Genetic Algorithms, with evaluation and visualization tools.

Quick Start

# Installation
git clone https://github.com/straightchlorine/fsga.git
cd fsga
uv venv && source .venv/bin/activate
uv pip install -e .

# Run example
python experiments/run_experiment.py

Basic Usage

from fsga.core.genetic_algorithm import GeneticAlgorithm
from fsga.datasets.loader import load_dataset
from fsga.evaluators.accuracy_evaluator import AccuracyEvaluator
from fsga.ml.models import ModelWrapper

# Load data and setup
X_train, X_test, y_train, y_test, _ = load_dataset('iris', split=True)
model = ModelWrapper('rf', n_estimators=50, random_state=42)
evaluator = AccuracyEvaluator(X_train, y_train, X_test, y_test, model)

# Run GA
from fsga.selectors.tournament_selector import TournamentSelector
from fsga.operators.uniform_crossover import UniformCrossover
from fsga.mutations.bitflip_mutation import BitFlipMutation

ga = GeneticAlgorithm(
    num_features=X_train.shape[1],
    evaluator=evaluator,
    selector=TournamentSelector(evaluator, tournament_size=3),
    crossover_operator=UniformCrossover(),
    mutation_operator=BitFlipMutation(probability=0.01),
    population_size=50,
    num_generations=100,
    early_stopping_patience=10
)

results = ga.evolve()
print(f"Accuracy: {results['best_fitness']:.2%}")
print(f"Features: {results['best_chromosome'].sum()}/{X_train.shape[1]}")

Key Features

  • Modular Design: Swappable operators, selectors, and evaluators
  • Multiple Operators: 4 crossover operators, 4 selection strategies, 3 fitness functions
  • Baseline Comparisons: Built-in RFE, LASSO, Mutual Information, Chi², ANOVA
  • Statistical Testing: Wilcoxon, Mann-Whitney, Cohen's d, Jaccard stability
  • Visualization: 9 plot functions for analysis and comparison
  • Experiment Framework: ExperimentRunner for reproducible experiments
  • Configuration: YAML-based configuration system

Architecture

fsga/
├── core/          # GA engine (genetic_algorithm, population)
├── operators/     # Crossover: uniform, single-point, two-point, multi-point
├── mutations/     # Mutation: bitflip
├── selectors/     # Selection: tournament, roulette, ranking, elitism
├── evaluators/    # Fitness: accuracy, F1, balanced accuracy
├── ml/            # Model wrappers (sklearn integration)
├── datasets/      # Dataset loaders (iris, wine, breast_cancer, digits)
├── analysis/      # Baselines + ExperimentRunner
├── visualization/ # 9 plot functions
└── utils/         # Config, metrics, serialization, logging

Documentation

  • Getting Started - Installation and basic usage
  • Tutorial - Step-by-step guide with examples
  • Architecture - System design and extension points
  • Project Plan - Status and roadmap
  • Module READMEs - See fsga/*/README.md for component details

Example Results

Breast Cancer Dataset (30 features → 14 features):

  • GA Accuracy: 98.3% with 48% of features
  • All Features: 95.7% with 100% of features
  • +2.6% accuracy, 52% dimensionality reduction

Iris Dataset (4 features → 2.6 features):

  • GA Accuracy: 97.7% with 65% of features
  • Selected: petal length, petal width

Wine Dataset (13 features → 7.2 features):

  • GA Accuracy: 100% with 55% of features

Running Experiments

# Full analysis (iris, wine, breast_cancer; 6 plots per dataset)
python experiments/run_experiment.py

# Quick test (single dataset, fewer runs)
python experiments/run_experiment.py --quick

# Specific datasets only
python experiments/run_experiment.py --datasets iris wine

# Without visualizations (faster)
python experiments/run_experiment.py --no-plots

# Results saved to: results/{mode}/{dataset}/

Tests

# Run all tests
uv run pytest tests/ -v

# With coverage
uv run pytest tests/ --cov=fsga --cov-report=html

# Current: 290 tests (about 67% line coverage)

Configuration

Example config (configs/default.yaml):

population_size: 50
num_generations: 100
mutation_rate: 0.01
crossover_rate: 0.8
early_stopping_patience: 10

dataset:
  name: iris
  test_size: 0.2

Load with:

from fsga.utils.config import Config
config = Config.from_file('configs/default.yaml')

License

MIT License - see LICENSE file for details.


To the only God, be honour and glory for ever and ever.

Metadata

Release files for fsga 1.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fsga 1.1.9
File Size Uploaded Provenance Actions
fsga-1.1.9.tar.gz 66.9 kB With provenance Details for fsga-1.1.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fsga 1.1.9
File Interpreter ABI Platform Actions
fsga-1.1.9-py3-none-any.whl Python 3 none any Details for fsga-1.1.9-py3-none-any.whl

Total release size: 123.2 kB

Release files / fsga-1.1.9.tar.gz

Download URL fsga-1.1.9.tar.gz
Size 66.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ea8c3e1f2c69198528d66f42add8815a4488022c8ef02363cec04da2414b3fd4
BLAKE2b-256 checksum
How to use checksums
83a8e264b541cef29734a1f438ede5042c4e2aba12fc1932c1c87c810a4df335
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / fsga-1.1.9-py3-none-any.whl

Download URL fsga-1.1.9-py3-none-any.whl
Size 56.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
515db9c5a2f1f429a67f74f1ed0aaba6df1d362c30dcd4cab9d62b49bdc8055d
BLAKE2b-256 checksum
How to use checksums
002c0b4b2b3b3a7fb83e4aa762d1d60f4578af171b7cb42656dabfdd45d1c8f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Security for fsga 1.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fsga-1.1.9.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page