ps-opt
This Python package provides a tool for hyperparameter tuning and feature selection in machine learning models using Particle Swarm Optimization (PSO) techniques. The package includes a vanilla PSO for feature selection, a vanilla PSO for hyperparameter tuning, and two different PSO variants for machine learning hyperparameter tuning.
Features
Vanilla PSO for Feature Selection: This feature uses the standard PSO algorithm to select the most optimal features for a given machine learning model. The algorithm works by searching the feature space and identifying a subset of features that maximizes the performance of the model.
Vanilla PSO for Hyperparameter Tuning: This feature uses the standard PSO algorithm to tune the hyperparameters of a given machine learning model. The algorithm works by searching the hyperparameter space and identifying a set of parameters that maximize the performance of the model.
PSO Variants for Hyperparameter Tuning: This package includes two different PSO variants for hyperparameter tuning. These variants offer different search strategies and can provide better results depending on the specific characteristics of the problem.
Cross-Validation: The package uses cross-validation in the hyperparameter tuning process to avoid overfitting and to ensure that the tuned parameters generalize well to unseen data.
Example Usage
The following is a basic example of how to use this package:
Installation
Install it using pip:
pip install ps-optimize
Hyperparameters Tuning
import pandas as pd
from sklearn.datasets import make_classification
from ps_opt.hyperparameters_tuning import ParticleSwarmSearchCV
from ps_opt.search_space_characteristics import Categorical, Real, Integer
from sklearn.linear_model import LogisticRegression
X, y = make_classification()
X = pd.DataFrame(X)
y = pd.Series(y)
search_space = {
"penalty": Categorical("l1", "l2", "elasticnet", None),
"max_iter": Integer(10, 20, "exponential"),
"tol": Real(.0001, .1, "uniform"),
"solver": Categorical('lbfgs', 'liblinear', 'newton-cg', 'sag', 'saga')
}
psocv = ParticleSwarmSearchCV(
search_space=search_space,
n_particles=30,
estimator=LogisticRegression,
cv=5,
scoring="accuracy",
max_iter=10,
n_jobs=1,
verbosity=0
)
psocv.fit(X, y)
print(f"Best Score: {psocv.best_score_}")
print(f"Best Parameters: {psocv.best_params_}")
print(f"Best Probabilities: {psocv.best_proba_}")
Feature Selection
import pandas as pd
from sklearn.datasets import make_classification
from ps_opt.feature_selection import ParticleSwarmFeatureSelectionCV
from ps_opt.search_space_characteristics import Categorical, Real, Integer
from sklearn.linear_model import LogisticRegression
X, y = make_classification()
X = pd.DataFrame(X)
y = pd.Series(y)
psocv = ParticleSwarmFeatureSelectionCV(
n_particles=30,
estimator=LogisticRegression,
cv=5,
scoring="accuracy",
max_iter=10,
n_jobs=-1,
verbosity=0
)
psocv.fit(X, y)
print(f"Best Score: {psocv.best_score_}")
print(f"Best Features: {psocv.best_features_}")
print(f"Best Probabilities: {psocv.best_proba_}")
Metadata
Release files for ps-optimize 2.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ps-optimize-2.0.4.tar.gz | 11.3 kB | Without provenance | Details for ps-optimize-2.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ps_optimize-2.0.4-py3-none-any.whl | Python 3 | none | any | Details for ps_optimize-2.0.4-py3-none-any.whl |
Total release size: 27.5 kB
Release files / ps-optimize-2.0.4.tar.gz
| Download URL | ps-optimize-2.0.4.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26bcb7b4fb97f7e4b2a7e8e37e40b9a4f6e0b992cfa977923fbf34e63c71722b
|
|
BLAKE2b-256 checksum How to use checksums |
032cf3a8e57729473759ffbc397a4f43dcf4f3661a5bc6b31dcea3b910a40917
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.1
|
Release files / ps_optimize-2.0.4-py3-none-any.whl
| Download URL | ps_optimize-2.0.4-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2bd19ad9adfd47d66967a45ad4d01a893332c74b2adaad5da830cca1bd34220
|
|
BLAKE2b-256 checksum How to use checksums |
e06c4fcc9c00c2b6afe8870c85fcfa2bee3c6d1c985c38b6ef4b85e729986733
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.1
|
Security for ps-optimize 2.0.4
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.