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,
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
Close
Hashes for sklearn-genetic-opt-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e9ef38c7043ad98fa8f899eb76a7812af51f023d1e5e8b6a50e551517dde861 |
|
MD5 | 989c4d14d9a317be5ed7d2e6e08a99ce |
|
BLAKE2b-256 | b90f5dc126e7786432dc9d6eb2392e29016804d255c56d38d716489e85b6fefe |
Close
Hashes for sklearn_genetic_opt-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74ed3db81cb8c0a234213438bde810c565aec0302da185831b531291cf13476b |
|
MD5 | 697b9162ba96dff4cefe2f69f468f47b |
|
BLAKE2b-256 | 523561c74096a3b37a6b610f0d716ec946bfca3aa4bb43a5862d33c4957fc121 |