{"id":34107601,"url":"https://github.com/ayhaidar/pspso","last_synced_at":"2026-03-17T22:37:23.341Z","repository":{"id":57455324,"uuid":"247231008","full_name":"ayhaidar/pspso","owner":"ayhaidar","description":"pspso is a package for selecting machine learning algorithms parameters based on PSO algorithm. ","archived":false,"fork":false,"pushed_at":"2025-11-08T09:02:45.000Z","size":8266,"stargazers_count":9,"open_issues_count":1,"forks_count":6,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-12T16:55:40.753Z","etag":null,"topics":["auto-ml","hyperparameter-optimization"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ayhaidar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-14T07:23:23.000Z","updated_at":"2025-10-01T07:57:37.000Z","dependencies_parsed_at":"2022-09-10T00:40:55.176Z","dependency_job_id":null,"html_url":"https://github.com/ayhaidar/pspso","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ayhaidar/pspso","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayhaidar%2Fpspso","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayhaidar%2Fpspso/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayhaidar%2Fpspso/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayhaidar%2Fpspso/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ayhaidar","download_url":"https://codeload.github.com/ayhaidar/pspso/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayhaidar%2Fpspso/sbom","scorecard":{"id":220567,"data":{"date":"2025-08-11","repo":{"name":"github.com/ayhaidar/pspso","commit":"0a755973cd101b17e883d3d159b46111966c5636"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":8,"reason":"binaries present in source code","details":["Warn: binary detected: dist/pspso-0.1.3-py3-none-any.whl:1","Warn: binary detected: pspso/__pycache__/pspso.cpython-36.pyc:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-17T02:22:41.421Z","repository_id":57455324,"created_at":"2025-08-17T02:22:41.421Z","updated_at":"2025-08-17T02:22:41.421Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30633477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auto-ml","hyperparameter-optimization"],"created_at":"2025-12-14T18:07:37.107Z","updated_at":"2026-03-17T22:37:23.334Z","avatar_url":"https://github.com/ayhaidar.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![image](LOGO.png)\n\n\nWelcome to pspso's documentation!\n=================================\n\nOverview and Installation\n=========================\n\nOverview\n--------\n\n**pspso** is a python library for selecting machine learning algorithms\nparameters. The first version supports two single algorithms:\nMulti-Layer Perceptron (MLP) and Support Vector Machine (SVM). It\nsupports two ensembles: Extreme Gradient Boosting (XGBoost) and Gradient\nBoosting Decision Trees (GBDT).\n\nTwo types of machine learning tasks are supported by pspso:\n\n-   Regression.\n-   Binary classification.\n\nThree scores are supported in the first version of pspso:\n\n-   **Regression** :\n\n    \u003e -   Root Mean Square Error (RMSE)\n\n-   **Binary Classication** :\n\n    \u003e -   Area under the Curve (AUC) of the Receiver Operating\n    \u003e     Characteristic (ROC)\n    \u003e -   Accuracy\n\nInstallation\n------------\n\nclone the repo, then from the local cloned directory run:\n\n```bash\npip install -e .\n```\n\nPaper\n===============\n\nHaidar A, Field M, Sykes J, Carolan M, Holloway L. PSPSO: A package for parameters selection using particle swarm optimization. SoftwareX. 2021 Jul 1;15:100706.\n\nhttps://www.sciencedirect.com/science/article/pii/S2352711021000510\n\nUsage\n=====\n\nMLP Example (Binary Classification)\n-----------------------------------\n\n**pspso** is used to select the machine learning algorithms parameters.\nBelow is an example for using the pspso to select the parameters of the\nMLP. pspso handles the MLP random weights intialization issue that may\ncause losing the best solution in consecutive iterations.\n\nThe following example demonstrates the selection process of the MLP\nparameters. A variable named *params* was not given by the user. Hence,\nthe default search space of the MLP is loaded. This search space\ncontains five parameters:\n\n``` {.sourceCode .python}\nparams = {\"optimizer\": [\"RMSprop\", \"adam\", \"sgd\",'adamax','nadam','adadelta'] ,\n      \"learning_rate\":  [0.1,0.3,2],\n      \"neurons\": [1,40,0],\n      \"hiddenactivation\": ['relu','sigmoid','tanh'],\n      \"activation\":['relu','sigmoid','tanh']} \n```\n\nThe task and the score were defined as *binary classification* and *auc*\nrespectively. Then, the PSO was used to select the parameters of the\nMLP. Results are provided back to the user through the\n**print\\_results()** function.\n\n``` {.sourceCode .python}\nfrom sklearn.preprocessing import MinMaxScaler\nfrom pspso import pspso\nfrom sklearn import datasets\nfrom sklearn.model_selection import train_test_split\n\nbreastcancer = datasets.load_breast_cancer()\ndata=breastcancer.data#get the breast cancer dataset input features\ntarget=breastcancer.target# target\nX_train, X_test, Y_train, Y_test = train_test_split(data, target,test_size=0.1,random_state=42,stratify=target)\nnormalize = MinMaxScaler(feature_range=(0,1))#normalize input features \nX_train=normalize.fit_transform(X_train)\nX_test=normalize.transform(X_test)\nX_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train,test_size=0.15,random_state=42,stratify=Y_train)\np=pspso(estimator='mlp',task='binary classification', score='auc')\npos,cost,duration,model,optimizer=p.fitpspso(X_train,Y_train,X_val,Y_val)\np.print_results()#print the results\ntestscore=pspso.predict(p.model,p.estimator,p.task,p.score, X_test, Y_test)\nprint(1-testscore)\n```\n\nIn this example, four parameters were examined: optimizer,\nlearning\\_rate, hiddenactivation, and activation. The number of neurons\nin the hidden layer was kept as default.\n\nOutput:\n\n``` {.sourceCode .python}\nEstimator: mlp\nTask: binary classification\nSelection type: PSO\nNumber of attempts:50\nTotal number of combinations: 45360\nParameters:\n{'optimizer': 'nadam', 'learning_rate': 0.29, 'neurons': 4, 'hiddenactivation': 'sigmoid', 'activation': 'sigmoid'}\nGlobal best position: [3.8997699  0.28725911 4.21218138 1.41200923 0.84643591]\nGlobal best cost: 0.0\nTime taken to find the set of parameters: 160.3374378681183\nNumber of particles: 5\nNumber of iterations: 10\n0.9867724867724867\n```\n\nXGBoost Example (Binary Classification)\n---------------------------------------\n\n``` {.sourceCode .python}\nfrom sklearn.preprocessing import MinMaxScaler\nfrom pspso import pspso\nfrom sklearn import datasets\nfrom sklearn.model_selection import train_test_split\n\nbreastcancer = datasets.load_breast_cancer()\ndata=breastcancer.data#get the breast cancer dataset input features\ntarget=breastcancer.target# target\nX_train, X_test, Y_train, Y_test = train_test_split(data, target,test_size=0.1,random_state=42,stratify=target)\nnormalize = MinMaxScaler(feature_range=(0,1))#normalize input features \nX_train=normalize.fit_transform(X_train)\nX_test=normalize.transform(X_test)\nX_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train,test_size=0.15,random_state=42,stratify=Y_train)\n\nparams = {\n        \"learning_rate\":  [0.01,0.2,2],\n        \"max_depth\": [1,10,0],\n        \"n_estimators\": [2,200,0],\n        \"subsample\": [0.7,1,1]}\np=pspso(estimator='xgboost',params=params,task='binary classification', score='auc')\npos,cost,duration,model,optimizer=p.fitpspso(X_train,Y_train,X_val,Y_val)\np.print_results()#print the results\ntestscore=pspso.predict(p.model,p.estimator,p.task,p.score, X_test, Y_test)\nprint(1-testscore)\n```\n\nXGBoost Example (Regression)\n----------------------------\n\nThe XGBoost is an implementation of boosting decision trees. Five\nparameters were utilized for selection: objective, learning rate,\nmaximum depth, number of estimators, and subsample. Three categorical\nvalues were selected for the objective parameter. The learning rate\nparameter values range between *0.01* and *0.2* with *2* decimal point,\nmaximum depth ranges between *1* and *10* with *0* decimal points\n*(1,2,3,4,5,6,7,8,9,10)*, etc. The task and score are selected as\nregression and RMSE respectively. The number of particles and number of\niterations can be left as default values if needed. Then, a pspso\ninstance is created. By applying the fitpspso function, the selection\nprocess is applied. Finally, results are printed back to the user. The\nbest model, best parameters, score, time, and other details will be\nsaved in the created instance for the user to check.\n\n``` {.sourceCode .python}\nfrom sklearn.preprocessing import MinMaxScaler\nfrom pspso import pspso\nfrom sklearn import datasets\nfrom sklearn.model_selection import train_test_split\n\nboston_data = datasets.load_boston()\ndata=boston_data.data\ntarget=boston_data.target\n\nX_train, X_test, Y_train, Y_test = train_test_split(data, target,test_size=0.1,random_state=42)\nnormalize = MinMaxScaler(feature_range=(0,1))#normalize input features\nnormalizetarget = MinMaxScaler(feature_range=(0,1))#normalize target\n\nX_train=normalize.fit_transform(X_train)\nX_test=normalize.transform(X_test)\nY_train=normalizetarget.fit_transform(Y_train.reshape(-1,1))\nY_test=normalizetarget.transform(Y_test.reshape(-1,1))\n\nX_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train,test_size=0.25,random_state=42)\nparams = {\n        \"objective\":['reg:tweedie',\"reg:linear\",\"reg:gamma\"],\n        \"learning_rate\":  [0.01,0.2,2],\n        \"max_depth\": [1,10,0],\n        \"n_estimators\": [2,200,0],\n        \"subsample\": [0.7,1,1]}\np=pspso(estimator='xgboost',params=params,task='regression', score='rmse')\npos,cost,duration,model,optimizer=p.fitpspso(X_train,Y_train,X_val,Y_val)\np.print_results()#print the results\ntestscore=pspso.predict(p.model,p.estimator,p.task,p.score, X_test, Y_test)\nprint(testscore)\n```\n\nUser Input\n----------\n\nThe user is required to select the type of the algorithm ('mlp', 'svm',\n'xgboost', 'gbdt'); the task type ('binary\nclassification','regression'), score ('rmse', 'acc', or 'auc'). The user\ncan keep the parameters variable empty, where a default set of\nparameters and ranges is loaded for each algorithm.\n\n``` {.sourceCode .python}\nfrom pspso import pspso\ntask='binary classification'\nscore='auc'\np=pspso.pspso('xgboost',None,task,score)\n```\n\nPspso allows the user to provide a range of parameters for exploration.\nThe parameters vary between each algorithm. Any parameter supported by\nthe Scikit-Learn API for GBDT and XGBoost can be added to the selection\nprocess. A set of parameters that contains five XGBoost parameters is\nshown below. The parameters are encoded in JSON object that consists of\n*key,value* pairs:\n\n``` {.sourceCode .python}\nparams = {\"objective\":['reg:tweedie',\"reg:linear\",\"reg:gamma\"],\n        \"learning_rate\":  [0.01,0.2,2],\n        \"max_depth\": [1,10,0],\n        \"n_estimators\": [2,200,0],\n        \"subsample\": [0.7,1,1]}\n```\n\nThe key can be any parameter belonging to to the algorithm under\ninvestigation. The value is a list. Pspso will check the type of the\nfirst element in the list, which will determine if the values of the\nparameter are categorical or numerical.\n\n**Categorical Parameters**\n\nIf the parameter values are *categorical*, string values are expected to\nbe found in the list, as shown in *objective* parameter. The values in\nthe list will be automatically mapped into a list of integers, where\neach integer represents a value in the original list. The order of the\nvalues inside the list affect the position of the value in the search\nspace.\n\n**Numerical Parameters**\n\nIf the parameter is numerical, a list of three elements [lb,ub, rv] is\nexpected to be found:\n\n-   **lb**: repesents the lowest value in the search space\n-   **ub**: represents the maximum value in the search space\n-   **rv**: represents the number of decimal points the parameter values\n    are rounded to before being added for training the algorithm\n\nFor e.g if you want pspso to select n\\_estimators, add the following\nlist *[2,200,0]*. By that, the lowest n\\_estimators will be *2*, the\nhighest to be examined is *200*, and each possible value is rounded to\nan integer value ( *0* decimal points).\n\n**Other parameters**\n\nThe user is given the chance to handle some of the default parameters\nsuch as the number of epochs in the MLP. Although this parameter can be\noptimized, but its not encouraged. The user can modify this by changing\na pspso class instance. For e.g., to change the number of epochs from\ndefault to 10 in MLP training:\n\n``` {.sourceCode .python}\nfrom pspso import pspso\ntask='binary classification'\nscore='auc'\np=pspso.pspso('mlp',None,task,score)# in case of empty set of params (None) default search space is loaded\np.defaultparams['epochs']=10\n```\n\nThe verbosity can be modified for any algorithm, which allows showing\ndetails of the training process:\n\n``` {.sourceCode .python}\nfrom pspso import pspso\ntask='binary classification'\nscore='auc'\np=pspso.pspso('mlp',None,task,score)\np.verbosity=1\n```\n\nEarly stopping rounds can alos be modified, the user can set a value\ndifferent to the default value:\n\n``` {.sourceCode .python}\nfrom pspso import pspso\ntask='binary classification'\nscore='auc'\np=pspso.pspso('xgboost',None,task,score)\np.early_stopping=10\n```\n\nOther parameters such that n\\_jobs in XGBoost can also be modified\nbefore the start of the selection process.\n\n\n\nContributing\n============\n\nPull requests are welcome. For major changes, please open an issue first\nto discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\nWe are working towards adding the cross validation support that will\ntake the training data and number of folds, then split the records and\ntrain each fold. Finally, the average performance is retuned to the\nuser.\n\nWe are also working on adding multi-class classification and data\noversampling techniques.\n\n\nSteps for adding another machine learning algorithm\n===================================================\n\nThe main reason behind the development of this package is to facilitate\nthe use of the algorithms with a minimum amount of code required.\nHowever, the steps to add an algorithm are followed:\n\n-   **Step 1:** Add a condition in the **get\\_default\\_search\\_space()**\n    function to include the new algorithm default search space\n    parameters with upper/lower bounds\n-   **Step 2:** Add a default search space based on the algorithm and\n    the task (binary classification or regression) to the\n    **get\\_default\\_params()** function\n-   **Step 3:** Create a function **forward\\_prop\\_algorithmname()**\n    that accepts parameters (similar to\n    forward\\_prop\\_gbdt,forward\\_prop\\_svm) and returns two variables:\n    the model and fitness value\n-   **Step 4:** Add a condition in the function **f()** to forward the\n    task to the function created in Step 3\n-   **Step 5:** Add a condition in the function **predict()** to allow\n    building the model using the function created in Step 3\n\nLicense\n=======\n\nCopyright (c) [2020] [Ali Haidar]\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayhaidar%2Fpspso","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayhaidar%2Fpspso","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayhaidar%2Fpspso/lists"}