{"id":14384667,"url":"https://github.com/yandongliu/learningjs","last_synced_at":"2026-01-10T07:44:01.372Z","repository":{"id":15801927,"uuid":"18541373","full_name":"yandongliu/learningjs","owner":"yandongliu","description":"javascript implementation of logistic regression/c4.5 decision tree","archived":false,"fork":false,"pushed_at":"2019-05-15T22:43:01.000Z","size":94,"stargazers_count":65,"open_issues_count":1,"forks_count":16,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-16T11:18:17.752Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.cs.cmu.edu/~yandongl/learningjs/decision-tree-demo.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yandongliu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-08T01:50:30.000Z","updated_at":"2023-06-19T00:33:52.000Z","dependencies_parsed_at":"2022-08-25T14:30:43.550Z","dependency_job_id":null,"html_url":"https://github.com/yandongliu/learningjs","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/yandongliu%2Flearningjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandongliu%2Flearningjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandongliu%2Flearningjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandongliu%2Flearningjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yandongliu","download_url":"https://codeload.github.com/yandongliu/learningjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230716604,"owners_count":18269805,"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":[],"created_at":"2024-08-28T18:01:33.902Z","updated_at":"2026-01-10T07:44:01.313Z","avatar_url":"https://github.com/yandongliu.png","language":"JavaScript","readme":"LearningJS: A Javascript Implementation of Logistic Regression and C4.5 Decision Tree Algorithms\n==========\nAuthor: Yandong Liu. Email: yandongl @ cs.cmu.edu\n\n# Update\nI've made some update on the data loading logic so now it reads in csv-format file. Previous version is still accessible but it's no longer supported.\n\n# Introduction\nJavascript implementation of several machine learning algorithms including Decision Tree and Logistic Regression this far. More to come.\n\n# Online Demo\nHere's a online [demo](http://www.cs.cmu.edu/~yandongl/learningjs/decision-tree-demo.html) with visualization and a few datasets.\n\n# Data format\nInput files need to be in CSV-format with 1st line being feature names. One of the features has to be called 'label'. E.g.  \n\u003cpre\u003e\noutlook, temp, humidity, wind, label\ntext, real, text, text, feature_type\n'Sunny',80,'High', 'Weak', 'No'\n'Sunny',82,'High', 'Strong', 'No'\n'Overcast',73,'High', 'Weak', 'Yes' \n\u003c/pre\u003e\nThere's also an optional 2nd line for feature types and the 'label' column for 2nd line has to be called 'feature_type'. This is useful if feature types are mixed. For Logistic Regression, all features should be real numbers. E.g.\n\u003cpre\u003e\nlabel,a,b,c,d,e,f,g,h,i,j,k,l,m\n1,1,0.72694,1.4742,0.32396,0.98535,1,0.83592,0.0046566,0.0039465,0.04779,0.12795,0.016108,0.0052323\n2,2,0.74173,1.5257,0.36116,0.98152,0.99825,0.79867,0.0052423,0.0050016,0.02416,0.090476,0.0081195,0.002708\n3,3,0.76722,1.5725,0.38998,0.97755,1,0.80812,0.0074573,0.010121,0.011897,0.057445,0.0032891,0.00092068\n1,4,0.73797,1.4597,0.35376,0.97566,1,0.81697,0.0068768,0.0086068,0.01595,0.065491,0.0042707,0.0011544\n\u003c/pre\u003e\n\n\n# Usage\nData loading: data_util.js provides three methods:\n\n * `loadTextFile`: the csv-format file will be loaded from disk and columns are parsed as strings unless 2nd line specifies feature types.\n * `loadRealFile`: the csv-format file will be loaded from disk and columns are parsed as real numbers.\n * `loadString`: a big string will be chopped into lines and columns are parsed as strings unless 2nd line specifies feature types.\n\nIn the loading callback function you will obtain a data object D on which you can apply the learning methods. Note that only Decision Tree supports both real and categorical features. Logistic Regression works on real features only.  \n\n\n```javascript\n\u003cscript type=\"text/javascript\" src=\"http://code.jquery.com/jquery-1.8.1.min.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"data_util.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"learningjs.js\"\u003e\u003c/script\u003e\nloadString(content, function(D) {\n  var tree = new learningjs.tree();\n  tree.train(D, function(model, err){\n    if(err) {\n      console.log(err);\n    } else {\n      model.calcAccuracy(D.data, D.targets, function(acc, correct, total){\n        console.log( 'training: got '+correct +' correct out of '+total+' examples. accuracy:'+(acc*100.0).toFixed(2)+'%');\n      });\n    }\n  });\n}); \n```\n\n# Use in Nodejs\nSimilarly you need to import the lib and do the same:\n\n```javascript \nvar learningjs = require('learningjs.js');\nvar data_util = require('data_util.js');\nvar tree = new learningjs.tree();\ndata_util.loadRealFile(fn_csv, function(D) {\n\n  //normalize data\n  data_util.normalize(D.data, D.nfeatures); \n\n  //logistic regression. following params are optional\n  D.optimizer = 'sgd'; //default choice. other choice is 'gd'\n  D.learning_rate = 0.005;\n  D.l2_weight = 0.0;\n  D.iterations = 1000; //increase number of iterations for better performance\n\n  new learningjs.logistic().train(D, function(model, err){\n    if(err) {\n      console.log(err);\n    } else {\n      model.calcAccuracy(D.data, D.targets, function(acc, correct, total){\n        console.log('training: got '+correct +' correct out of '+total+' examples. accuracy:'+(acc*100.0).toFixed(2)+'%');\n      });\n      data_util.loadRealFile(fn_test, function(T) {\n        model.calcAccuracy(T.data, T.targets, function(acc, correct, total){\n          console.log('    test: got '+correct +' correct out of '+total+' examples. accuracy:'+(acc*100.0).toFixed(2)+'%');\n        });\n      });\n    }\n  });\n}); \n```\n\n# License\nMIT\n","funding_links":[],"categories":["Javascript","JavaScript","[](https://github.com/josephmisiti/awesome-machine-learning/blob/master/README.md#javascript)Javascript"],"sub_categories":["Tools","[Tools](#tools-1)","Speech Recognition"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyandongliu%2Flearningjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyandongliu%2Flearningjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyandongliu%2Flearningjs/lists"}