All Projects → timzatko → Sklearn-Nature-Inspired-Algorithms

timzatko / Sklearn-Nature-Inspired-Algorithms

Licence: MIT license
Nature-inspired algorithms for hyper-parameter tuning of Scikit-Learn models.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Sklearn-Nature-Inspired-Algorithms

machine-learning-capstone-project
This is the final project for the Udacity Machine Learning Nanodegree: Predicting article retweets and likes based on the title using Machine Learning
Stars: ✭ 28 (+75%)
Mutual labels:  scikit-learn
A-Detector
⭐ An anomaly-based intrusion detection system.
Stars: ✭ 69 (+331.25%)
Mutual labels:  scikit-learn
sklearn-audio-classification
An in-depth analysis of audio classification on the RAVDESS dataset. Feature engineering, hyperparameter optimization, model evaluation, and cross-validation with a variety of ML techniques and MLP
Stars: ✭ 31 (+93.75%)
Mutual labels:  scikit-learn
ray tutorial
An introductory tutorial about leveraging Ray core features for distributed patterns.
Stars: ✭ 67 (+318.75%)
Mutual labels:  scikit-learn
IBM-final-project-Machine-Learning
Final project of IBM's course https://www.coursera.org/learn/machine-learning-with-python on coursera
Stars: ✭ 33 (+106.25%)
Mutual labels:  scikit-learn
books
A collection of online books for data science, computer science and coding!
Stars: ✭ 29 (+81.25%)
Mutual labels:  scikit-learn
dbt-ml-preprocessing
A SQL port of python's scikit-learn preprocessing module, provided as cross-database dbt macros.
Stars: ✭ 128 (+700%)
Mutual labels:  scikit-learn
scikit-activeml
Our package scikit-activeml is a Python library for active learning on top of SciPy and scikit-learn.
Stars: ✭ 46 (+187.5%)
Mutual labels:  scikit-learn
osprey
🦅Hyperparameter optimization for machine learning pipelines 🦅
Stars: ✭ 71 (+343.75%)
Mutual labels:  scikit-learn
vector space modelling
NLP in python Vector Space Modelling and document classification NLP
Stars: ✭ 16 (+0%)
Mutual labels:  scikit-learn
Football Prediction Project
This project will pull past game data from api-football, and use these statistics to predict the outcome of future premier league matches through machine learning.
Stars: ✭ 44 (+175%)
Mutual labels:  scikit-learn
playground
A Streamlit application to play with machine learning models directly from the browser
Stars: ✭ 48 (+200%)
Mutual labels:  scikit-learn
opfunu
A collection of Benchmark functions for numerical optimization problems (https://opfunu.readthedocs.io)
Stars: ✭ 31 (+93.75%)
Mutual labels:  nature-inspired-algorithms
kaggle-titanic
Titanic assignment on Kaggle competition
Stars: ✭ 30 (+87.5%)
Mutual labels:  scikit-learn
kdd99-scikit
Solutions to kdd99 dataset with Decision tree and Neural network by scikit-learn
Stars: ✭ 50 (+212.5%)
Mutual labels:  scikit-learn
five-minute-midas
Predicting Profitable Day Trading Positions using Decision Tree Classifiers. scikit-learn | Flask | SQLite3 | pandas | MLflow | Heroku | Streamlit
Stars: ✭ 41 (+156.25%)
Mutual labels:  scikit-learn
abess
Fast Best-Subset Selection Library
Stars: ✭ 266 (+1562.5%)
Mutual labels:  scikit-learn
object detector
Object detector from HOG + Linear SVM framework
Stars: ✭ 24 (+50%)
Mutual labels:  scikit-learn
scikit-learn
به فارسی، برای مشارکت scikit-learn
Stars: ✭ 19 (+18.75%)
Mutual labels:  scikit-learn
mash 2016 sklearn intro
Material for the MASH course on introduction to scikit-learn
Stars: ✭ 16 (+0%)
Mutual labels:  scikit-learn

Nature-Inspired Algorithms for scikit-learn

CI Maintainability PyPI - Python Version PyPI version PyPI downloads Fedora package

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

To install this package on Fedora, run:

$ dnf install python3-sklearn-nature-inspired-algorithms

Usage

The usage is similar to using sklearn's GridSearchCV. Refer to the documentation for more detailed guides and more examples.

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, 40, 2),
    'min_samples_split': range(2, 20, 2), 
    'max_features': ["auto", "sqrt", "log2"],
}

clf = RandomForestClassifier(random_state=42)

nia_search = NatureInspiredSearchCV(
    clf,
    param_grid,
    algorithm='hba', # hybrid bat algorithm
    population_size=50,
    max_n_gen=100,
    max_stagnating_gen=10,
    runs=3,
    random_state=None, # or any number if you want same results on each run
)

nia_search.fit(X_train, y_train)

# the best params are stored in nia_search.best_params_
# finally you can train your model with best params from nia search
new_clf = RandomForestClassifier(**nia_search.best_params_, random_state=42)

Also you plot the search process with line plot or violin plot.

from sklearn_nature_inspired_algorithms.helpers import score_by_generation_lineplot, score_by_generation_violinplot

# line plot will plot all of the runs, you can specify the metric to be plotted ('min', 'max', 'median', 'mean')
score_by_generation_lineplot(nia_search, metric='max')

# in violin plot you need to specify the run to be plotted
score_by_generation_violinplot(nia_search, run=0)

Jupyter notebooks with full examples are available in here.

Using a Custom Nature-Inspired Algorithm

If you do not want to use any 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 behavior. Refer to their documentation and examples for the usage.

Note: Use version >2.x.x of NiaPy package

from niapy.algorithms.basic import GeneticAlgorithm

algorithm = GeneticAlgorithm() # when custom algorithm is provided random_state is ignored
algorithm.set_parameters(NP=50, Ts=5, Mr=0.25)

nia_search = NatureInspiredSearchCV(
    clf,
    param_grid,
    algorithm=algorithm,
    population_size=50,
    max_n_gen=100,
    max_stagnating_gen=20,
    runs=3,
)

nia_search.fit(X_train, y_train)

Contributing

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].