{"id":19267059,"url":"https://github.com/mljs/pls","last_synced_at":"2025-04-21T19:32:40.312Z","repository":{"id":33783031,"uuid":"37449370","full_name":"mljs/pls","owner":"mljs","description":"PLS regression algorithm","archived":false,"fork":false,"pushed_at":"2023-10-02T07:53:10.000Z","size":7221,"stargazers_count":10,"open_issues_count":5,"forks_count":5,"subscribers_count":14,"default_branch":"main","last_synced_at":"2024-09-19T15:18:34.677Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"http://mljs.github.io/pls/","language":"JavaScript","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/mljs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-15T07:11:44.000Z","updated_at":"2024-07-22T16:40:20.000Z","dependencies_parsed_at":"2023-01-15T02:30:46.943Z","dependency_job_id":"c6a2de1f-8aa1-45a5-a2ed-a631052cf401","html_url":"https://github.com/mljs/pls","commit_stats":{"total_commits":117,"total_committers":12,"mean_commits":9.75,"dds":0.6495726495726496,"last_synced_commit":"ba2660e1e1bc14230363b3c4a5e12bb30636a896"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fpls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fpls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fpls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fpls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mljs","download_url":"https://codeload.github.com/mljs/pls/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223876433,"owners_count":17218388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["hacktoberfest"],"created_at":"2024-11-09T20:09:53.136Z","updated_at":"2025-04-21T19:32:40.307Z","avatar_url":"https://github.com/mljs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Partial Least Squares (PLS), Kernel-based Orthogonal Projections to Latent Structures (K-OPLS) and NIPALS based OPLS\n\n[![NPM version][npm-image]][npm-url]\n[![build status][ci-image]][ci-url]\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7314529.svg)](https://doi.org/10.5281/zenodo.7314529)\n[![npm download][download-image]][download-url]\n\nPLS regression algorithm based on the Yi Cao implementation:\n\n[PLS Matlab code](http://www.mathworks.com/matlabcentral/fileexchange/18760-partial-least-squares-and-discriminant-analysis)\n\nK-OPLS regression algorithm based on [this paper](http://onlinelibrary.wiley.com/doi/10.1002/cem.1071/abstract).\n\n[K-OPLS Matlab code](http://kopls.sourceforge.net/download.shtml)\n\nOPLS implementation based on the R package [Metabomate](https://github.com/kimsche/MetaboMate) using NIPALS factorization loop.\n\n## installation\n\n`$ npm i ml-pls`\n\n## Usage\n\n### [PLS](./src/PLS.js)\n\n```js\nimport PLS from 'ml-pls';\n\nconst X = [\n  [0.1, 0.02],\n  [0.25, 1.01],\n  [0.95, 0.01],\n  [1.01, 0.96],\n];\nconst Y = [\n  [1, 0],\n  [1, 0],\n  [1, 0],\n  [0, 1],\n];\nconst options = {\n  latentVectors: 10,\n  tolerance: 1e-4,\n};\n\nconst pls = new PLS(options);\npls.train(X, Y);\n```\n\n### [OPLS-R](./src/OPLS.js)\n\n```js\nimport {\n  getNumbers,\n  getClassesAsNumber,\n  getCrossValidationSets,\n} from 'ml-dataset-iris';\nimport { OPLS } from 'ml-pls';\n\nconst cvFolds = getCrossValidationSets(7, { idx: 0, by: 'trainTest' });\nconst data = getNumbers();\nconst irisLabels = getClassesAsNumber();\n\nconst model = new OPLS(data, irisLabels, { cvFolds });\nconsole.log(model.mode); // 'regression'\n```\n\nThe OPLS class is intended for exploratory modeling, that is not for the creation of predictors. Therefore there is a built-in k-fold cross-validation loop and Q2y is an average over the folds.\n\n```js\nconsole.log(model.model[0].Q2y);\n```\n\nshould give 0.9209227614652857\n\n### [OPLS-DA](./src/OPLS.js)\n\n```js\nimport {\n  getNumbers,\n  getClasses,\n  getCrossValidationSets,\n} from 'ml-dataset-iris';\nimport { OPLS } from 'ml-pls';\n\nconst cvFolds = getCrossValidationSets(7, { idx: 0, by: 'trainTest' });\nconst data = getNumbers();\nconst irisLabels = getClasses();\n\nconst model = new OPLS(data, irisLabels, { cvFolds });\nconsole.log(model.mode); // 'discriminantAnalysis'\nconsole.log(model.model[0].auc); // 0.5366666666666665,\n```\n\nIf for some reason a predictor is necessary the following code may serve as an example\n\n### [Prediction](./src/OPLS.js)\n\n```js\nimport {\n  getNumbers,\n  getClassesAsNumber,\n  getCrossValidationSets,\n} from 'ml-dataset-iris';\nimport { OPLS } from 'ml-pls';\n\n// get frozen folds for testing purposes\nconst { testIndex, trainIndex } = getCrossValidationSets(7, {\n  idx: 0,\n  by: 'trainTest',\n})[0];\n\n// Getting the data of selected fold\nconst irisNumbers = getNumbers();\nconst testData = irisNumbers.filter((el, idx) =\u003e testIndex.includes(idx));\nconst trainingData = irisNumbers.filter((el, idx) =\u003e trainIndex.includes(idx));\n\n// Getting the labels of selected fold\nconst irisLabels = getClassesAsNumber();\nconst testLabels = irisLabels.filter((el, idx) =\u003e testIndex.includes(idx));\nconst trainingLabels = irisLabels.filter((el, idx) =\u003e trainIndex.includes(idx));\n\nconst model = new OPLS(trainingData, trainingLabels);\nconsole.log(model.mode); // 'discriminantAnalysis'\nconst prediction = model.predict(testData, { trueLabels: testLabels });\n// Get the predicted Q2 value\nconsole.log(prediction.Q2y); // 0.9247698398971457\n```\n\n### [K-OPLS](./src/KOPLS.js)\n\n```js\nimport Kernel from 'ml-kernel';\nimport { KOPLS } from 'ml-pls';\n\nconst kernel = new Kernel('gaussian', {\n  sigma: 25,\n});\n\nconst X = [\n  [0.1, 0.02],\n  [0.25, 1.01],\n  [0.95, 0.01],\n  [1.01, 0.96],\n];\nconst Y = [\n  [1, 0],\n  [1, 0],\n  [1, 0],\n  [0, 1],\n];\n\nconst cls = new KOPLS({\n  orthogonalComponents: 10,\n  predictiveComponents: 1,\n  kernel: kernel,\n});\n\ncls.train(X, Y);\n\nconst {\n  prediction, // prediction\n  predScoreMat, // Score matrix over prediction\n  predYOrthVectors, // Y-Orthogonal vectors over prediction\n} = cls.predict(X);\n\nconsole.log(prediction);\nconsole.log(predScoreMat);\nconsole.log(predYOrthVectors);\n```\n\n## [API Documentation](http://mljs.github.io/pls/)\n\n## License\n\n[MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/ml-pls.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/ml-pls\n[ci-image]: https://github.com/mljs/pls/workflows/Node.js%20CI/badge.svg?branch=main\n[ci-url]: https://github.com/mljs/pls/actions?query=workflow%3A%22Node.js+CI%22\n[download-image]: https://img.shields.io/npm/dm/ml-pls.svg?style=flat-square\n[download-url]: https://npmjs.org/package/ml-pls\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fpls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmljs%2Fpls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fpls/lists"}