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 PyPI version PyPI downloads

Nature inspired algorithms for hyper-parameter tuning in scikit-learn. 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='fa', # firefly algorithm
    population_size='25',
    max_n_gen=100,
    max_stagnating_gen=5,
)

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 sklearn_nature_inspired_algorithms.model_selection import NatureInspiredSearchCV

from NiaPy.algorithms.basic import GeneticAlgorithm

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

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

nia_search = NatureInspiredSearchCV(
    clf,
    param_grid,
    algorithm=algorithm,
    max_n_gen=100,
    max_stagnating_gen=5,
)

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.1.1.tar.gz (5.3 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.1.1.tar.gz.

File metadata

File hashes

Hashes for sklearn_nature_inspired_algorithms-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cde5cc8f28057a49c6b5c3069224393faea240d3bd9cad5e9e78111863950b3c
MD5 13445b74ce8c13f9e1d17ca87aa3a84e
BLAKE2b-256 e05f588a6f4e03782949408177e98799db55254890bb156283f6a361691424b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sklearn_nature_inspired_algorithms-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 943e5080c583d72c5607605dcfeb2b70646d2d2150da2ec494468a20551fd9e5
MD5 56bcdb2de3f516aca2512f10ef0308e3
BLAKE2b-256 514741acb0a5889256ba06d7b73220b00a8a955e5f7441fdb3c795889b7b8b19

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