Sklearn models hyperparameters tuning using genetic algorithms
Project description
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.tree import DecisionTreeClassifier
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,
criteria='max',
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
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
Built Distribution
File details
Details for the file sklearn-genetic-opt-0.1.1.tar.gz
.
File metadata
- Download URL: sklearn-genetic-opt-0.1.1.tar.gz
- Upload date:
- Size: 8.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | bae1e366bd01f40c610b35346f913bb8fd26257c2ce2e0b445843a32e051f7fc |
|
MD5 | 36910f94bffa7de49c1e42b308c601d5 |
|
BLAKE2b-256 | defedcd5e7a8b8f598181d7a720dcaa920d243dbaa63744a055af57507b19c9e |
File details
Details for the file sklearn_genetic_opt-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: sklearn_genetic_opt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff74a42a5fde4ed4a3a16f31959ce7c220edb93a14632927cec2bd093aef66a8 |
|
MD5 | 7e68177f70940b2ad225d5c347692667 |
|
BLAKE2b-256 | 58e6b6ebfc5819f5f7590797c9316fbcf4a53641c3ccb16246564fcd2defe3bb |