Skip to main content

Sklearn models hyperparameters tuning using genetic algorithms

Project description

Build Status Codecov PyPI Version Python Version

Sklearn-genetic-opt

Sklearn models hyperparameters tuning using genetic algorithms

Usage:

Install sklearn-genetic-opt

It's advised to install sklearn-genetic using a virtual env, inside the env use:

pip install sklearn-genetic-opt

Example

from sklearn_genetic import GASearchCV
from sklearn.linear_model import SGDClassifier
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_digits
from sklearn.metrics import accuracy_score


data = load_digits() 
y = data['target']
X = data['data'] 

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)

clf = DecisionTreeClassifier()

evolved_estimator = GASearchCV(clf,
                               cv=3,
                               scoring='accuracy',
                               population_size=16,
                               generations=30,
                               tournament_size=3,
                               elitism=True,
                               crossover_probability=0.9,
                               mutation_probability=0.05,
                               continuous_parameters={'min_weight_fraction_leaf': (0, 0.5)},
                               categorical_parameters={'criterion': ['gini', 'entropy']},
                               integer_parameters={'max_depth': (2, 20), 'max_leaf_nodes': (2, 30)},
                               encoding_length=10,
                               n_jobs=-1)

evolved_estimator.fit(X_train,y_train)
print(evolved_estimator.best_params_)
y_predict_ga = evolved_estimator.predict(X_test)
print(accuracy_score(y_test,y_predict_ga))

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-genetic-opt-0.1.0.dev0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

sklearn_genetic_opt-0.1.0.dev0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file sklearn-genetic-opt-0.1.0.dev0.tar.gz.

File metadata

  • Download URL: sklearn-genetic-opt-0.1.0.dev0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for sklearn-genetic-opt-0.1.0.dev0.tar.gz
Algorithm Hash digest
SHA256 6aea0f9edabbbac68d084bc64750b1bb7f58e72536b54fb35df5ed9ac9ee2579
MD5 39ddfaf20df1395be5771756e138e346
BLAKE2b-256 e9ddfdfc953d9b794cb0ded4200ae288718f17ecae8abdd8eea5c251dad85e48

See more details on using hashes here.

File details

Details for the file sklearn_genetic_opt-0.1.0.dev0-py3-none-any.whl.

File metadata

  • Download URL: sklearn_genetic_opt-0.1.0.dev0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for sklearn_genetic_opt-0.1.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f7d1b7ab85b4f4784144fbb2deae16e1c5ffd3d07d1338a95759a95ce7f2554
MD5 47dcd4f26f08499f08fd3d32927cd782
BLAKE2b-256 9fc10f89759f6bd6fc8aa72279265ac8dd9c51bc1ba1a169a7e34e5a9333cad4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page