{"id":26730376,"url":"https://github.com/stefano-meschiari/sklearn-classifiers-playground","last_synced_at":"2025-04-14T10:12:36.464Z","repository":{"id":42417420,"uuid":"453553965","full_name":"stefano-meschiari/sklearn-classifiers-playground","owner":"stefano-meschiari","description":"Web app using Pyodide to demo different types of Scikit-learn classifiers","archived":false,"fork":false,"pushed_at":"2022-04-16T01:30:19.000Z","size":5635,"stargazers_count":12,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T10:12:32.934Z","etag":null,"topics":["pyodide","python","react","sklearn"],"latest_commit_sha":null,"homepage":"","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/stefano-meschiari.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":"2022-01-30T00:37:54.000Z","updated_at":"2024-06-06T04:55:44.000Z","dependencies_parsed_at":"2022-08-24T20:50:28.915Z","dependency_job_id":null,"html_url":"https://github.com/stefano-meschiari/sklearn-classifiers-playground","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/stefano-meschiari%2Fsklearn-classifiers-playground","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-meschiari%2Fsklearn-classifiers-playground/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-meschiari%2Fsklearn-classifiers-playground/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-meschiari%2Fsklearn-classifiers-playground/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefano-meschiari","download_url":"https://codeload.github.com/stefano-meschiari/sklearn-classifiers-playground/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860182,"owners_count":21173342,"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":["pyodide","python","react","sklearn"],"created_at":"2025-03-27T23:29:31.914Z","updated_at":"2025-04-14T10:12:36.436Z","avatar_url":"https://github.com/stefano-meschiari.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scikit-learn Classifiers Playground\n\n**[Try it online](https://www.stefanom.io/sklearn-classifiers-playground/)**\n\n## What is it?\n:construction: **NOTE: This document is a work in progress!** :construction:\n\n![](img/playground.png)\n\nThis web application interactively trains Scikit-learn classification algorithms and plots class boundaries using Matplotlib. This is implemented without any server component using [Pyodide](https://pyodide.org/en/stable/) -- **it's all running on your browser**! \n\nThe following classifiers can be trained:\n\n* Logistic Regression\n* Decision Tree\n* Random Forest\n* SVM (RBF kernel)\n* K-nearest neighbors\n* A 2-layer Neural Network\n* Gaussian Process\n\non a variety of 2D datasets.\n\n\n## Implementation\nBriefly, a Python class (`SklearnClassifiers`, defined in [sklearn_classifiers.py](py/sklearn_classifiers.py))  first defines the set of inputs (the type of classifier, the dataset, a random seed, etc.). This set of inputs is used to build the React components in the sidebar ([PyodideApplet](src/PyodideApplet.js)).\n\nOn first run, or when the value of the inputs change, the React app calls the `compute()` method defined in `SklearnClassifiers`. This method trains a classifier,  computes a 2D matrix of predictions, plots them on a Matplotlib figure, base64-encodes the output image, and returns it to the React app. Finally, the React app displays the base64-encoded image in an `\u003cimg\u003e` tag.\n\nNote that I also implemented (in a very flawed way) the ability to add additional \"custom\" points to the dataset simply by clicking on the plot. Each point added by the user is draggable. Since the underlying plot is a static image, I overlay draggable elements whose coordinates are sent to the Python code, translated into the Matplotlib figure coordinate space, and added to the dataset used to train the classifier. I will probably remove this code eventually, since it is very hacky.\n\n#### TODOs\n- [ ] Run Pyodide in a Web Worker to avoid locking the main thread\n- [ ] Document development in a blog post\n- [ ] Switch from Matplotlib to an SVG-based plotting library\n- [ ] Add the ability to set hyperparameters for each type of classifier\n- [ ] Mobile-friendly layout\n- [ ] Add the ability to import a 2D dataset (e.g. as a CSV file)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefano-meschiari%2Fsklearn-classifiers-playground","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefano-meschiari%2Fsklearn-classifiers-playground","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefano-meschiari%2Fsklearn-classifiers-playground/lists"}