hyperparameter-optimizer 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,207 @@
1
+ Metadata-Version: 2.4
2
+ Name: hyperparameter-optimizer
3
+ Version: 0.1.2
4
+ Summary: A lightweight Python library for hyperparameter tuning using Metaheuristic algorithms.
5
+ Home-page: https://github.com/real-ahmed-moussa/hyperparameter-optimizer
6
+ Author: Dr. Ahmed Moussa
7
+ Author-email: ahmedyosrihamdy@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: numpy
16
+ Requires-Dist: scikit-learn
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: license
24
+ Dynamic: requires-dist
25
+ Dynamic: requires-python
26
+ Dynamic: summary
27
+
28
+ # Hyperparameter Optimizer
29
+
30
+ A lightweight and flexible Python library for hyperparameter tuning using metaheuristic techniques.
31
+ Currently, the library includes **Particle Swarm Optimization (PSO)** and **Pattern Search (PS)** only.
32
+
33
+ Designed for Scikit-learn-compatible models, this package offers an easy-to-use interface for optimizing model performance in just a few lines.
34
+
35
+ ![PyPI version](https://img.shields.io/pypi/v/hyperparameter-optimizer.svg)
36
+ ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
37
+ [![Downloads](https://static.pepy.tech/personalized-badge/hyperparameter-optimizer?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Downloads)](https://pepy.tech/project/hyperparameter-optimizer)
38
+
39
+ ---
40
+
41
+ ## 📦 Installation
42
+
43
+ Install from PyPI:
44
+
45
+ ```bash
46
+ pip install hyperparameter-optimizer
47
+ ```
48
+
49
+ ---
50
+
51
+ ## ⚙️ Features
52
+
53
+ - ✅ Metaheuristic optimization using Particle Swarm Optimization (PSO) and Pattern Search (PS)
54
+ - ✅ Supports continuous, integer, and categorical hyperparameters
55
+ - ✅ Compatible with any Scikit-learn estimator
56
+ - ✅ Custom scoring metrics
57
+ - ✅ Cross-validation built-in
58
+ - ✅ Verbose logging and full traceability
59
+
60
+ ---
61
+
62
+ ## 📚 API Reference
63
+
64
+ ### `HyperparameterOptimizer`
65
+
66
+ ```python
67
+ HyperparameterOptimizer(
68
+ obj_func, # machine learning model or pipeline being created
69
+ params, # dictionary of parameters for which the model is to be optimized.
70
+ scoring, # scoring metric (e.g., 'accuracy')
71
+ opt_type="max", # type of optimization: "max" for maximization (default) or "min" for minimization.
72
+ cv=5, # number of cross-validation folds
73
+ verbose=1 # binary with a value of 1 (default) to show iteration information.
74
+ )
75
+ ```
76
+
77
+ ### `optimizePSO`
78
+
79
+ ```python
80
+ optimizePSO(
81
+ features, # training features.
82
+ target, # training target.
83
+ nParticles, # number of particles in the swarm.
84
+ bounds, # list of (min, max) tuples or a categorical list of choices.
85
+ # if either min/max is non-integer, the algorithm shall consider them as floats (i.e., continuous).
86
+ w=0.5, # inertia weight.
87
+ c1=1, # cognitive weight.
88
+ c2=1, # social weight.
89
+ maxIter=20, # maximum number of iterations.
90
+ mutation_prob=0.1 # mtation probability -- for discrete hyperparameters.
91
+ )
92
+ ```
93
+
94
+ ### `optimizePS`
95
+
96
+ ```python
97
+ optimizePS(
98
+ features, # training features.
99
+ target, # training target.
100
+ bounds, # list of (min, max) tuples or a categorical list of choices.
101
+ # if either min/max is non-integer, the algorithm shall consider them as floats (i.e., continuous).
102
+ mesh_size_coeff=0.6, # mesh size coefficient.
103
+ acc_coeff=1, # acceleration/mesh expansion coefficient.
104
+ contr_coeff=0.5, # mesh contraction coefficient.
105
+ search_method="gps", # new points exploration method; either 'gps' or 'mads'.
106
+ min_mesh_ratio=0.001, # minimum mesh size as a percentage of parameter range.
107
+ maxIter=25 # maximum number of iterations.
108
+ )
109
+ ```
110
+
111
+ ---
112
+
113
+ ## 🚀 Quickstart
114
+
115
+ Here's a basic example of how to use **Hyperparameter Optimizer** with a Scikit-learn model (e.g., `RandomForestClassifier`):
116
+
117
+ ```python
118
+ from sklearn.datasets import load_iris
119
+ from sklearn.ensemble import RandomForestClassifier
120
+ from hyperparameter_optimizer import HyperparameterOptimizer
121
+
122
+ # Load data
123
+ X, y = load_iris(return_X_y=True)
124
+
125
+ # Define parameter space
126
+ param_space = {
127
+ 'n_estimators': [],
128
+ 'max_depth': [],
129
+ 'criterion': []
130
+ }
131
+
132
+ # Initialize the optimizer
133
+ optimizer = HyperparameterOptimizer(
134
+ obj_func=RandomForestClassifier(),
135
+ params=param_space,
136
+ scoring='accuracy',
137
+ opt_type='max',
138
+ cv=3,
139
+ verbose=1
140
+ )
141
+
142
+ # Run optimization
143
+ # [1] Particle Swarm Optimization
144
+ particles, Gbest_history, Gbest_pos, Gbest_score = optimizer.optimizePSO(
145
+ features = X,
146
+ target = y,
147
+ nParticles = 10,
148
+ bounds = [(10, 1000), (1, 10), ['gini', 'entropy']],
149
+ maxIter = 10
150
+ )
151
+ print("Best Params:", Gbest_pos)
152
+ print("Best Score:", Gbest_score)
153
+
154
+ # [2] Pattern Search Optimization
155
+ Gbest_history2, Gbest_pos2, Gbest_score2 = optimizer.optimizePS(
156
+ features = X,
157
+ target = y,
158
+ bounds = [(10, 1000), (1, 10), ['gini', 'entropy']],
159
+ mesh_size_coeff = 0.1,
160
+ acc_coeff = 1,
161
+ contr_coeff = 0.50,
162
+ maxIter = 10
163
+ )
164
+ print("Best Params:", Gbest_pos2)
165
+ print("Best Score:", Gbest_score2)
166
+
167
+ ```
168
+
169
+ ---
170
+
171
+ ## 🧠 How It Works
172
+
173
+ This library leverages two optimization techniques—**Particle Swarm Optimization (PSO) and Pattern Search (PS)**—to explore the hyperparameter space effectively.
174
+
175
+ Particle Swarm Optimization simulates a group of particles (candidate solutions) moving through the search space. Each particle adjusts its position based on its own best-known position and the best-known position among its peers, enabling a balance between exploration and exploitation as the swarm converges toward an optimal solution.
176
+
177
+ Pattern Search is a derivative-free method that explores the neighborhood of a current solution by systematically evaluating a set of search directions. If an improved solution is found, the algorithm moves in that direction and repeats the process, enabling efficient local refinement without relying on gradient information.
178
+
179
+ Together, these methods provide robust global and local search capabilities for hyperparameter tuning.
180
+
181
+ ---
182
+
183
+ ## 📜 License
184
+
185
+ This project is licensed under the **MIT License**.
186
+ © 2025 **Dr. Ahmed Moussa**
187
+
188
+ ---
189
+
190
+ ## 🤝 Contributing
191
+
192
+ Pull requests are welcome.
193
+ For major changes, please open an issue first to discuss what you would like to change.
194
+
195
+ ---
196
+
197
+ ## 📫 Contact
198
+
199
+ For feedback, bugs, or collaboration ideas:
200
+
201
+ - **GitHub**: [@real-ahmed-moussa](https://github.com/real-ahmed-moussa)
202
+
203
+ ---
204
+
205
+ ## ⭐️ Show Your Support
206
+
207
+ If you find this project useful, consider giving it a ⭐️ on [GitHub](https://github.com/real-ahmed-moussa/hyperparameter-optimizer)!
@@ -0,0 +1,180 @@
1
+ # Hyperparameter Optimizer
2
+
3
+ A lightweight and flexible Python library for hyperparameter tuning using metaheuristic techniques.
4
+ Currently, the library includes **Particle Swarm Optimization (PSO)** and **Pattern Search (PS)** only.
5
+
6
+ Designed for Scikit-learn-compatible models, this package offers an easy-to-use interface for optimizing model performance in just a few lines.
7
+
8
+ ![PyPI version](https://img.shields.io/pypi/v/hyperparameter-optimizer.svg)
9
+ ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
10
+ [![Downloads](https://static.pepy.tech/personalized-badge/hyperparameter-optimizer?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Downloads)](https://pepy.tech/project/hyperparameter-optimizer)
11
+
12
+ ---
13
+
14
+ ## 📦 Installation
15
+
16
+ Install from PyPI:
17
+
18
+ ```bash
19
+ pip install hyperparameter-optimizer
20
+ ```
21
+
22
+ ---
23
+
24
+ ## ⚙️ Features
25
+
26
+ - ✅ Metaheuristic optimization using Particle Swarm Optimization (PSO) and Pattern Search (PS)
27
+ - ✅ Supports continuous, integer, and categorical hyperparameters
28
+ - ✅ Compatible with any Scikit-learn estimator
29
+ - ✅ Custom scoring metrics
30
+ - ✅ Cross-validation built-in
31
+ - ✅ Verbose logging and full traceability
32
+
33
+ ---
34
+
35
+ ## 📚 API Reference
36
+
37
+ ### `HyperparameterOptimizer`
38
+
39
+ ```python
40
+ HyperparameterOptimizer(
41
+ obj_func, # machine learning model or pipeline being created
42
+ params, # dictionary of parameters for which the model is to be optimized.
43
+ scoring, # scoring metric (e.g., 'accuracy')
44
+ opt_type="max", # type of optimization: "max" for maximization (default) or "min" for minimization.
45
+ cv=5, # number of cross-validation folds
46
+ verbose=1 # binary with a value of 1 (default) to show iteration information.
47
+ )
48
+ ```
49
+
50
+ ### `optimizePSO`
51
+
52
+ ```python
53
+ optimizePSO(
54
+ features, # training features.
55
+ target, # training target.
56
+ nParticles, # number of particles in the swarm.
57
+ bounds, # list of (min, max) tuples or a categorical list of choices.
58
+ # if either min/max is non-integer, the algorithm shall consider them as floats (i.e., continuous).
59
+ w=0.5, # inertia weight.
60
+ c1=1, # cognitive weight.
61
+ c2=1, # social weight.
62
+ maxIter=20, # maximum number of iterations.
63
+ mutation_prob=0.1 # mtation probability -- for discrete hyperparameters.
64
+ )
65
+ ```
66
+
67
+ ### `optimizePS`
68
+
69
+ ```python
70
+ optimizePS(
71
+ features, # training features.
72
+ target, # training target.
73
+ bounds, # list of (min, max) tuples or a categorical list of choices.
74
+ # if either min/max is non-integer, the algorithm shall consider them as floats (i.e., continuous).
75
+ mesh_size_coeff=0.6, # mesh size coefficient.
76
+ acc_coeff=1, # acceleration/mesh expansion coefficient.
77
+ contr_coeff=0.5, # mesh contraction coefficient.
78
+ search_method="gps", # new points exploration method; either 'gps' or 'mads'.
79
+ min_mesh_ratio=0.001, # minimum mesh size as a percentage of parameter range.
80
+ maxIter=25 # maximum number of iterations.
81
+ )
82
+ ```
83
+
84
+ ---
85
+
86
+ ## 🚀 Quickstart
87
+
88
+ Here's a basic example of how to use **Hyperparameter Optimizer** with a Scikit-learn model (e.g., `RandomForestClassifier`):
89
+
90
+ ```python
91
+ from sklearn.datasets import load_iris
92
+ from sklearn.ensemble import RandomForestClassifier
93
+ from hyperparameter_optimizer import HyperparameterOptimizer
94
+
95
+ # Load data
96
+ X, y = load_iris(return_X_y=True)
97
+
98
+ # Define parameter space
99
+ param_space = {
100
+ 'n_estimators': [],
101
+ 'max_depth': [],
102
+ 'criterion': []
103
+ }
104
+
105
+ # Initialize the optimizer
106
+ optimizer = HyperparameterOptimizer(
107
+ obj_func=RandomForestClassifier(),
108
+ params=param_space,
109
+ scoring='accuracy',
110
+ opt_type='max',
111
+ cv=3,
112
+ verbose=1
113
+ )
114
+
115
+ # Run optimization
116
+ # [1] Particle Swarm Optimization
117
+ particles, Gbest_history, Gbest_pos, Gbest_score = optimizer.optimizePSO(
118
+ features = X,
119
+ target = y,
120
+ nParticles = 10,
121
+ bounds = [(10, 1000), (1, 10), ['gini', 'entropy']],
122
+ maxIter = 10
123
+ )
124
+ print("Best Params:", Gbest_pos)
125
+ print("Best Score:", Gbest_score)
126
+
127
+ # [2] Pattern Search Optimization
128
+ Gbest_history2, Gbest_pos2, Gbest_score2 = optimizer.optimizePS(
129
+ features = X,
130
+ target = y,
131
+ bounds = [(10, 1000), (1, 10), ['gini', 'entropy']],
132
+ mesh_size_coeff = 0.1,
133
+ acc_coeff = 1,
134
+ contr_coeff = 0.50,
135
+ maxIter = 10
136
+ )
137
+ print("Best Params:", Gbest_pos2)
138
+ print("Best Score:", Gbest_score2)
139
+
140
+ ```
141
+
142
+ ---
143
+
144
+ ## 🧠 How It Works
145
+
146
+ This library leverages two optimization techniques—**Particle Swarm Optimization (PSO) and Pattern Search (PS)**—to explore the hyperparameter space effectively.
147
+
148
+ Particle Swarm Optimization simulates a group of particles (candidate solutions) moving through the search space. Each particle adjusts its position based on its own best-known position and the best-known position among its peers, enabling a balance between exploration and exploitation as the swarm converges toward an optimal solution.
149
+
150
+ Pattern Search is a derivative-free method that explores the neighborhood of a current solution by systematically evaluating a set of search directions. If an improved solution is found, the algorithm moves in that direction and repeats the process, enabling efficient local refinement without relying on gradient information.
151
+
152
+ Together, these methods provide robust global and local search capabilities for hyperparameter tuning.
153
+
154
+ ---
155
+
156
+ ## 📜 License
157
+
158
+ This project is licensed under the **MIT License**.
159
+ © 2025 **Dr. Ahmed Moussa**
160
+
161
+ ---
162
+
163
+ ## 🤝 Contributing
164
+
165
+ Pull requests are welcome.
166
+ For major changes, please open an issue first to discuss what you would like to change.
167
+
168
+ ---
169
+
170
+ ## 📫 Contact
171
+
172
+ For feedback, bugs, or collaboration ideas:
173
+
174
+ - **GitHub**: [@real-ahmed-moussa](https://github.com/real-ahmed-moussa)
175
+
176
+ ---
177
+
178
+ ## ⭐️ Show Your Support
179
+
180
+ If you find this project useful, consider giving it a ⭐️ on [GitHub](https://github.com/real-ahmed-moussa/hyperparameter-optimizer)!