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.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
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.dev0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aea0f9edabbbac68d084bc64750b1bb7f58e72536b54fb35df5ed9ac9ee2579 |
|
MD5 | 39ddfaf20df1395be5771756e138e346 |
|
BLAKE2b-256 | e9ddfdfc953d9b794cb0ded4200ae288718f17ecae8abdd8eea5c251dad85e48 |
Close
Hashes for sklearn_genetic_opt-0.1.0.dev0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f7d1b7ab85b4f4784144fbb2deae16e1c5ffd3d07d1338a95759a95ce7f2554 |
|
MD5 | 47dcd4f26f08499f08fd3d32927cd782 |
|
BLAKE2b-256 | 9fc10f89759f6bd6fc8aa72279265ac8dd9c51bc1ba1a169a7e34e5a9333cad4 |