PSO meet hyperparameter tuning.
Project description
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_}")
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ps-optimize-2.0.4.tar.gz.
File metadata
- Download URL: ps-optimize-2.0.4.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26bcb7b4fb97f7e4b2a7e8e37e40b9a4f6e0b992cfa977923fbf34e63c71722b
|
|
| MD5 |
94ecad86232dbeed36b4a7d747d96ae1
|
|
| BLAKE2b-256 |
032cf3a8e57729473759ffbc397a4f43dcf4f3661a5bc6b31dcea3b910a40917
|
File details
Details for the file ps_optimize-2.0.4-py3-none-any.whl.
File metadata
- Download URL: ps_optimize-2.0.4-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2bd19ad9adfd47d66967a45ad4d01a893332c74b2adaad5da830cca1bd34220
|
|
| MD5 |
2142433ed9ddece59814f91659c710bb
|
|
| BLAKE2b-256 |
e06c4fcc9c00c2b6afe8870c85fcfa2bee3c6d1c985c38b6ef4b85e729986733
|