{"id":20789539,"url":"https://github.com/victorqribeiro/mlp","last_synced_at":"2025-05-05T19:44:02.090Z","repository":{"id":128647098,"uuid":"170809830","full_name":"victorqribeiro/MLP","owner":"victorqribeiro","description":"A multilayer perceptron in JavaScript","archived":false,"fork":false,"pushed_at":"2019-03-11T23:46:59.000Z","size":23,"stargazers_count":20,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T23:11:08.092Z","etag":null,"topics":["javascript","multilayer-perceptron","neural-network"],"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/victorqribeiro.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-02-15T05:59:18.000Z","updated_at":"2025-03-18T08:05:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"f4cc175f-0b60-4239-bd20-aac73b5d3a60","html_url":"https://github.com/victorqribeiro/MLP","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/victorqribeiro%2FMLP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorqribeiro%2FMLP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorqribeiro%2FMLP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorqribeiro%2FMLP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/victorqribeiro","download_url":"https://codeload.github.com/victorqribeiro/MLP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252564099,"owners_count":21768588,"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":["javascript","multilayer-perceptron","neural-network"],"created_at":"2024-11-17T15:24:47.377Z","updated_at":"2025-05-05T19:44:02.060Z","avatar_url":"https://github.com/victorqribeiro.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MLP - Multilayer Perceptron\n\nA multilayer perceptron implementation in JavaScript.\n\n## About\n\nThis is my implementation of a [MLP](https://en.wikipedia.org/wiki/Multilayer_perceptron) in JavaScript.\nIt's comes along with a matrix library to help with the matrix multiplications.\nRight now the code is untested and only with basic checks, but I'm still working on it. \nThere's a *s* variable commented out in the code, it can be used to measure the error over iterations.\nThe error should get smaller as the MLP gets trained. The dataset used in the html example was taken from [here](https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data).\n\n## How to use\n\nLet's suppose you have the following data set:\n\n| Height (cm) | Weight (kg) | Class (0-1) |\n|-------------|-------------|-------------|\n| 180         | 80          | 0           |\n| 175         | 67          | 0           |\n| 100         | 30          | 1           |\n| 120         | 32          | 1           |\n\n0 - adult  \n1 - child\n\nYou need to process the table to this format:\n\n```\nconst x = [\n\t[180, 80],\n\t[175, 67],\n\t[100, 30],\n\t[120, 32]\n];\n\nconst y = [\n\t[1,0],\n\t[1,0],\n\t[0,1],\n\t[0,1]\n];\n```\n\nNote that different from my [perceptron](https://github.com/perceptron) the labels are now [one-hot encoded](https://en.wikipedia.org/wiki/One-hot)\n\nThen just create a new MLP passing the number of inputs, the number of nodes in the hidden layer, the number of outputs,\nthe learning rate and the number of iterations.\n\n\n```\nconst nn = new MLP( x[0].length, x[0].length * 2, 2, 0.03, 500 );\n```\n\nCall the fit function\n\n```\nnn.fit( x, y );\n```\n\nAnd you're all set to make predictions\n\n```\nnn.predict( [178, 70] )\n```\n\nThere's also a [shuffle](https://datascience.stackexchange.com/questions/24511/why-should-the-data-be-shuffled-for-machine-learning-tasks) function that can be used before the training.\n\n```\nnn.shuffle( x, y );\n```\n\n## Applications\n\n[I trained my neural network to detect when I'm in front of the PC](https://github.com/victorqribeiro/faceRecognition).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorqribeiro%2Fmlp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictorqribeiro%2Fmlp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorqribeiro%2Fmlp/lists"}