Feature Selection with Genetic Algorithm
Project description
GeneticAlgorithmFeatureSelection
Feature Selection with Genetic Algorithm published in pypi.
Installation
pip install GeneticAlgorithmFeatureSelection
Example
The original example code can be found in test.py.
from sklearn.datasets import make_classification
import pandas as pd
from genetic_algoirthm.GA import GenticAlgorithmFeatureSelection
Define the sample classification dataset
x, y = make_classification(n_features=100, n_samples=2500)
input data must be pandas dataframe. we split target and features.
columns = [f'f_{i}' for i in range(1, 101)]
features = pd.DataFrame(x, columns=columns)
target = pd.DataFrame(y, columns=['target'])
run feature selection
GA = GenticAlgorithmFeatureSelection(features=features, target=target, population_size=100, elite_rate=0.5,
fitness_alpha=0.55, tourn_size=25, no_generation=50)
GA.run()
see history
history = GA.history
for generation, detail in history.items():
print(f'Generation :{generation}')
print(f'best score: {detail["best_score"]}')
print(f'features: {detail["selected_features"]}')
find best score and features in last generation
print(f'best score last generation :{GA.best_score}')
print(f'feature selected in last generation: {GA.selected_features}')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file GeneticAlgorithmFeaturesSelection-0.0.3.tar.gz
.
File metadata
- Download URL: GeneticAlgorithmFeaturesSelection-0.0.3.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc0f5aa8fff89e2d59f05b07c5f994bb8adf8ba0d41bee79ce6c1463f0d254e0 |
|
MD5 | fb785ed2152f9be007b266766d443abf |
|
BLAKE2b-256 | 5af7de1e33fea8ef894c444a1d0283d595cacf40a941354a44819a17e25b2cce |