{"id":23080600,"url":"https://github.com/chen0040/js-svm","last_synced_at":"2025-08-15T22:31:02.059Z","repository":{"id":57283696,"uuid":"91966540","full_name":"chen0040/js-svm","owner":"chen0040","description":"Package provides javascript implementation of support vector machines","archived":false,"fork":false,"pushed_at":"2017-06-02T16:45:46.000Z","size":40,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-10T00:26:33.822Z","etag":null,"topics":["binary-classification","kernel-svm","kernels","linear-svm","multi-class-classification","support-vector-machines"],"latest_commit_sha":null,"homepage":null,"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/chen0040.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-21T15:15:54.000Z","updated_at":"2019-07-25T03:41:11.000Z","dependencies_parsed_at":"2022-08-31T14:23:35.693Z","dependency_job_id":null,"html_url":"https://github.com/chen0040/js-svm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fjs-svm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fjs-svm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fjs-svm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fjs-svm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chen0040","download_url":"https://codeload.github.com/chen0040/js-svm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229964387,"owners_count":18152034,"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":["binary-classification","kernel-svm","kernels","linear-svm","multi-class-classification","support-vector-machines"],"created_at":"2024-12-16T13:15:26.338Z","updated_at":"2024-12-16T13:15:28.612Z","avatar_url":"https://github.com/chen0040.png","language":"JavaScript","readme":"# js-svm\nPackage provides javascript implementation of linear SVM and SVM with gaussian kernel\n\n[![Build Status](https://travis-ci.org/chen0040/js-svm.svg?branch=master)](https://travis-ci.org/chen0040/js-svm) [![Coverage Status](https://coveralls.io/repos/github/chen0040/js-svm/badge.svg?branch=master)](https://coveralls.io/github/chen0040/js-svm?branch=master) \n\n# Features\n\n* Support for binary classification\n* Support for multi-class classification \n\n# Install\n\n```bash\nnpm install js-svm\n```\n\n# Usage\n\n### SVM Binary Classifier\n\nThe sample code below show how to use SVM binary classifier on the iris datsets to classify whether a data row belong to species Iris-virginica:\n\n```javascript\nvar jssvm = require('js-svm');\nvar iris = require('js-datasets-iris');\n\nvar svm = new jssvm.BinarySvmClassifier();\n\niris.shuffle();\n\nvar trainingDataSize = Math.round(iris.rowCount * 0.9);\nvar trainingData = [];\nvar testingData = [];\nfor(var i=0; i \u003c iris.rowCount ; ++i) {\n   var row = [];\n   row.push(iris.data[i][0]); // sepalLength;\n   row.push(iris.data[i][1]); // sepalWidth;\n   row.push(iris.data[i][2]); // petalLength;\n   row.push(iris.data[i][3]); // petalWidth;\n   row.push(iris.data[i][4] == \"Iris-virginica\" ? 1.0 : 0.0); // output which is 1 if species is Iris-virginica; 0 otherwise\n   if(i \u003c trainingDataSize){\n        trainingData.push(row);\n   } else {\n       testingData.push(row);\n   }\n}\n\n\nvar result = svm.fit(trainingData);\n\nconsole.log(result);\n\nfor(var i=0; i \u003c testingData.length; ++i){\n   var predicted = svm.transform(testingData[i]);\n   console.log(\"actual: \" + testingData[i][4] + \" predicted: \" + predicted);\n}\n```\n\nTo configure the BinarySvmClassifier, use the following code when it is created:\n\n```javascript\nvar svm = new jssvm.BinarySvmClassifier({\n   alpha: 0.01, // learning rate\n   iterations: 1000, // maximum iterations\n   C: 5.0, // panelty term\n   trace: false // debug tracing\n});\n```\n\n### Multi-Class Classification using One-vs-All Logistic Regression\n\nThe sample code below illustrates how to run the multi-class classifier on the iris datasets to classifiy the species of each data row:\n\n```javascript\nvar jssvm = require('js-svm');\nvar iris = require('js-datasets-iris');\n\nvar classifier = new jssvm.MultiClassSvmClassifier();\n\niris.shuffle();\n\nvar trainingDataSize = Math.round(iris.rowCount * 0.9);\nvar trainingData = [];\nvar testingData = [];\nfor(var i=0; i \u003c iris.rowCount ; ++i) {\n   var row = [];\n   row.push(iris.data[i][0]); // sepalLength;\n   row.push(iris.data[i][1]); // sepalWidth;\n   row.push(iris.data[i][2]); // petalLength;\n   row.push(iris.data[i][3]); // petalWidth;\n   row.push(iris.data[i][4]); // output is species\n   if(i \u003c trainingDataSize){\n        trainingData.push(row);\n   } else {\n       testingData.push(row);\n   }\n}\n\n\nvar result = classifier.fit(trainingData);\n\nconsole.log(result);\n\nfor(var i=0; i \u003c testingData.length; ++i){\n   var predicted = classifier.transform(testingData[i]);\n   console.log(\"svm prediction testing: actual: \" + testingData[i][4] + \" predicted: \" + predicted);\n}\n```\n\nTo configure the MultiClassSvmClassifier, use the following code when it is created:\n\n```javascript\nvar classifier = new jssvm.MultiClassSvmClassifier({\n   alpha: 0.01, // learning rate\n   iterations: 1000, // maximum iterations\n   C: 5.0 // panelty term\n   sigma: 1.0 // the standard deviation for the gaussian kernel\n});\n```\n\n### Switch between linear and guassian kernel\n\nBy default the kernel used by the binary and multi-class classifier is \"linear\" which can be printed by:\n\n```javascript\nconsole.log(classifier.kernel);\n```\n\nTo switch to use gaussian kernel, put the property 'kernel: \"gaussian\"' in the config data when the classifier is created:\n\n```javascript\nvar svm = new jssvm.BinarySvmClassifier({\n   ...,\n   kernel: 'gaussian'\n});\n\n....\n\nvar svm = new jssvm.MultiClassSvmClassifier({\n   ...,\n   kernel: 'gaussian'\n});\n\n```\n\n\n### Usage In HTML\n\nInclude the \"node_modules/js-svm/build/jssvm.min.js\" (or \"node_modules/js-svm/src/jssvm.js\") in your HTML \\\u003cscript\\\u003e tag\n\nThe demo code in HTML can be found in the following files within the package:\n\n* [example-binary-classifier.html](https://rawgit.com/chen0040/js-svm/master/example-binary-classifier.html)\n* [example-multi-class-classifier.html](https://rawgit.com/chen0040/js-svm/master/example-multi-class-classifier.html)\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchen0040%2Fjs-svm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchen0040%2Fjs-svm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchen0040%2Fjs-svm/lists"}