Skperopt
A hyperopt wrapper - simplifying hyperparameter tuning with Scikit-learn style estimators.
Works with either classification evaluation metrics "f1", "auc" or "accuracy" AND regression "rmse" and "mse".
Installation:
pip install skperopt
Usage:
Just pass in an estimator, a parameter grid and Hyperopt will do the rest. No need to define objectives or write hyoperopt specific parameter grids.
Recipe (vanilla flavour):
- Import skperopt
- Initalize skperopt
- Run skperopt.HyperSearch.search
- Collect the results
Code example below.
import skperopt as sk
import pandas as pd
from sklearn.datasets import make_classification
from sklearn.neighbors import KNeighborsClassifier
#generate classification data
data = make_classification(n_samples=1000, n_features=10, n_classes=2)
X = pd.DataFrame(data[0])
y = pd.DataFrame(data[1])
#init the classifier
kn = KNeighborsClassifier()
param = {"n_neighbors": [int(x) for x in np.linspace(1, 60, 30)],
"leaf_size": [int(x) for x in np.linspace(1, 60, 30)],
"p": [1, 2, 3, 4, 5, 10, 20],
"algorithm": ['auto', 'ball_tree', 'kd_tree', 'brute'],
"weights": ["uniform", "distance"]}
#search parameters
search = sk.HyperSearch(kn, X, y, params=param)
search.search()
#gather and apply the best parameters
kn.set_params(**search.best_params)
#view run results
print(search.stats)
HyperSearch parameters
- est ([sklearn estimator] required)
any sklearn style estimator
- X ([pandas Dataframe] required)
your training data
- y ([pandas Dataframe] required)
your training data
- params ([dictionary] required)
a parameter search grid
- iters (default 500 [int])
number of iterations to try before early stopping
- time_to_search (default None [int])
time in seconds to run for before early stopping (None = no time limit)
- cv (default 5 [int])
number of folds to use in cross_vaidation tests
- cv_times (default 1 [int])
number of times to perfrom cross validation on a new random sample of the data -higher values decrease variance but increase run time
- randomState (default 10 [int])
random state for the data shuffling
- scorer (default "f1" [str])
type of evaluation metric to use - accepts classification "f1","auc","accuracy" or regression "rmse" and "mse"
- verbose (default 1 [int])
amount of verbosity
0 = none
1 = some
2 = debug
- random (default - False)
should the data be randomized during the cross validation
- foldtype (default "Kfold" [str])
type of folds to use - accepts "KFold", "Stratified"
HyperSearch methods
- HyperSearch.search() (None)
Used to search the parameter grid using hyperopt. No parameters need to be passed to the function. All parameters are set during initialization.
Testing
With 100 tests of 150 search iterations for both RandomSearch and Skperopt Searches.
Skperopt (hyperopt) performs better than a RandomSearch, producing higher average f1 score with a smaller standard deviation.
Skperopt Search Results
f1 score over 100 test runs:
Mean 0.9340930
Standard deviation 0.0062275
Random Search Results
f1 score over 100 test runs
Mean 0.927461652
Standard deviation 0.0063314
Updates
V0.0.73
- Added cv_times attr - runs the cross validation n times (ie cv (5x5) ) each iteration on a new randomly sampled data set this should reduce overfitting
V0.0.7
-
Added FIXED RMSE eval metric
-
Added MSE eval metric
Metadata
Release files for Skperopt 0.0.74
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Skperopt-0.0.74-py3-none-any.whl | Python 3 | none | any | Details for Skperopt-0.0.74-py3-none-any.whl |
Release files / Skperopt-0.0.74-py3-none-any.whl
| Download URL | Skperopt-0.0.74-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
683f8e255bafa16baf79bacaf3508352abea20bb339f18074a5984f203d439c8
|
|
BLAKE2b-256 checksum How to use checksums |
37050592301c94bf44c116c6a75bb1db949b31c40f36f4f8eba1c58ba4cb2a7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.3
|
Security for Skperopt 0.0.74
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.