Skip to main content

Search using nature inspired algorithms over specified parameter values for an sklearn estimator.

Project description

Nature Inspired Algorithms for scikit-learn

CI Maintainability PyPI - Python Version PyPI version PyPI downloads

Nature inspired algorithms for hyper-parameter tuning of scikit-learn models. This package uses algorithms implementation from NiaPy.

Installation

pip install sklearn-nature-inspired-algorithms

Usage

The usage is similar to using sklearn's GridSearchCV.

from sklearn_nature_inspired_algorithms.model_selection import NatureInspiredSearchCV
from sklearn.ensemble import RandomForestClassifier

param_grid = { 
    'n_estimators': range(20, 100, 20), 
    'max_depth': range(2, 20, 2),
    'min_samples_split': range(2, 20, 2), 
}

clf = RandomForestClassifier(random_state=42)

nia_search = NatureInspiredSearchCV(
    clf,
    param_grid,
    algorithm='ba', # bat algorithm
    population_size='15',
    max_n_gen=30,
    max_stagnating_gen=2,
)

nia_search.fit(X_train, y_train)

Jupyter notebooks with full examples are available in here.

Using custom nature inspired algorithm

If you do not want to use ony of the pre-defined algorithm configurations, you can use any algorithm from the NiaPy collection. This will allow you to have more control of the algorithm behaviour. Refer to their documentation and examples for the usage.

from NiaPy.algorithms.basic import GeneticAlgorithm

algorithm = GeneticAlgorithm()
algorithm.setParameters(NP=50, Ts=5, Mr=0.25)

nia_search = NatureInspiredSearchCV(
    clf,
    param_grid,
    algorithm=algorithm,
    population_size='15',
    max_n_gen=30,
    max_stagnating_gen=2,
)

nia_search.fit(X_train, y_train)

Contributing

Detailed information on the contribution guidelines are in the CONTRIBUTING.md.

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

sklearn_nature_inspired_algorithms-0.2.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file sklearn_nature_inspired_algorithms-0.2.0.tar.gz.

File metadata

File hashes

Hashes for sklearn_nature_inspired_algorithms-0.2.0.tar.gz
Algorithm Hash digest
SHA256 68456fe2c0719f3a95bca1f07d1e3cfa0b8ba410aa8c4193abcfbbdb40dd640b
MD5 42f2ab2b46ada160b75b0c8257a3c236
BLAKE2b-256 fcd3e855558bdafdefe0b8269414cb8fa9f7fce2b23726196d9c6189d0084d08

See more details on using hashes here.

File details

Details for the file sklearn_nature_inspired_algorithms-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sklearn_nature_inspired_algorithms-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b00fbc99f31341fe9aa76fb9192f295edc0ba20c2f258ccbbb0e11a68cd46ea7
MD5 4172ec9319bdb0fa75bf201572c4518b
BLAKE2b-256 9fef665b5396fdc1e951e2c589271e6da6a5296bc1d1130c1300540bb1b2b829

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