[{"id":"90ee7c5cf126aba4","type":"tab","label":"Popular ML Algorithms","disabled":false,"info":""},{"id":"e0f308659e515f62","type":"group","z":"90ee7c5cf126aba4","name":"","style":{"fill":"#e3f3d3","fill-opacity":"0.52","label":true},"nodes":["80d07308cbf532cf","febcc7a6291df344","7fee663f8de80449","e88d51dfec83bd25","7a1a0df33467d691","ba58ebd7cb508911","3530b3c70c572fae","59dd7ae2d05a469c","e3efc42859a53485","90a9661a8150cd41","795035ec76ba9fa2","cb03402819d9d203","1257750dc0020133","b69bb22f9380d6d2","2951b684c90afad0","bdd66cd79298a040","cdec698caa3bc993","f07acec55be5622e","251c5d82ca092385","2177305f18c9d7f9","205bfd0ad53f8c32","d7bb51b35101e96a","e88168d52ac07598","12e8c4dab2f08e73","41cfa308b6d362ca","eb25319f0fc18869","2c83edeceb16c3a8","ec7a2eb0108c6b2f","08bb0017370ee0cc","3b43f0e8320a2f93","15f021f2170ef627","6bda6c0de06edbfd","26738e34e35ee051","e3d599f2156d5ac2","90adba48e7057924","0ff77769a4c38273"],"x":34,"y":59,"w":632,"h":682},{"id":"a89bc0cef2ffe279","type":"group","z":"90ee7c5cf126aba4","name":"","style":{"fill":"#ffbfbf","label":true,"fill-opacity":"0.36"},"nodes":["3f1c257a38fc5d2f","56c6e21b631c1455","cb827096bc6143f2","8492468603b308fb","be9afb066dd5b51a","d85142d6d741b85f","54fa43481c02103d","ab25accd38811033","178899fc56bd8204","7f20dde4c03b45aa","1fadcf7775f3e5b3","e31f1c5e060aa92e","fe6b6251d3a39e47","0ecd44b3f1c7872b","699f10823e1bba29","7ae597bcb008b8b6","c2f7c74f01a4bb7d","ffc1d6cebe280389","a4b12b8fbf370c0d","1adb2d032b212dc8","c82d2f453fe4efb5","2ca495b38d7e9f02","6b24e3535207db2e","d75c2dad44d9f2e2","43de70a3f5e9bb92","511aa4ffaf263a1f","42690fa2c194c670","ad7a7db10225d11e","2529f222a8e6f40b","c23b860b438e3a72","972e06bf1aaeb612","caaf64c7f22651dc","1e75e6aba1b24649","d4dd878441c2322f"],"x":694,"y":59,"w":612,"h":542},{"id":"80d07308cbf532cf","type":"inject","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-svm","payload":"true","payloadType":"bool","x":190,"y":300,"wires":[["7fee663f8de80449"]]},{"id":"febcc7a6291df344","type":"debug","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":520,"y":300,"wires":[]},{"id":"7fee663f8de80449","type":"function","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"SVM","func":"var options = {\n  C: 0.01,\n  tol: 10e-4,\n  maxPasses: 10,\n  maxIterations: 10000,\n  kernel: 'rbf',\n  kernelOptions: {\n    sigma: 0.5\n  }\n};\n\nvar svm = new SVM(options);\n\n// Train the classifier - we give him an xor\nvar features = [[0,0],[0,1],[1,1],[1,0]];\nvar labels = [1, -1, 1, -1];\nsvm.train(features, labels);\n\n// Let's see how narrow the margin is\nvar margins = svm.margin(features);\n\n// Let's see if it is separable by testing on the training data\nsvm.predict(features); // [1, -1, 1, -1]\n\n// I want to see what my support vectors are\nvar supportVectors = svm.supportVectors();\n \n// Now we want to save the model for later use\nvar model = svm.toJSON();\n\n/// ... later, you can make predictions without retraining the model\nvar importedSvm = SVM.load(model);\nmsg.payload = importedSvm.predict(features); // [1, -1, 1, -1] \n\n\nreturn msg;\n\n// https://www.npmjs.com/package/ml-svm","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"SVM","module":"ml-svm"}],"x":330,"y":300,"wires":[["febcc7a6291df344"]]},{"id":"e88d51dfec83bd25","type":"function","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"NaiveBayes v1","func":"const naiveBayes = new NaiveBayes(\"en\");\n\nconst datasets = [\n    [\"You're doing good and expressive\", \"positive\"],\n    [\"You're doing wow and nice\", \"positive\"],\n    [\"What is this? very waste of time, and bad\", \"negative\"],\n];\n\nnaiveBayes.learn(...datasets);\n\nlet result = naiveBayes.classify(\n    \"This is bad, and you should try better because it waste my time\"\n);\nmsg.payload = result;\nreturn msg;\n\n//https://www.npmjs.com/package/idnaive","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"NaiveBayes","module":"idnaive"}],"x":360,"y":260,"wires":[["ba58ebd7cb508911"]]},{"id":"7a1a0df33467d691","type":"inject","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"idnaive","payload":"true","payloadType":"bool","x":190,"y":260,"wires":[["e88d51dfec83bd25"]]},{"id":"ba58ebd7cb508911","type":"debug","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":260,"wires":[]},{"id":"ef1c64320460a837","type":"comment","z":"90ee7c5cf126aba4","name":"Top 10 Machine Learning Algorithms","info":"https://www.simplilearn.com/10-algorithms-machine-learning-engineers-need-to-know-article","x":660,"y":20,"wires":[]},{"id":"3530b3c70c572fae","type":"function","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"Linear regression","func":"const x = [\n  [0, 0],\n  [1, 2],\n  [2, 3],\n  [3, 4]\n];\n// Y0 = X0 * 2, Y1 = X1 * 2, Y2 = X0 + X1\nconst y = [\n  [0, 0, 0],\n  [2, 4, 3],\n  [4, 6, 5],\n  [6, 8, 7]\n];\nconst mlr = new MLR(x, y);\nconsole.log(mlr);\n//weights Non standardized regression coefficient\n//stdWeights Standardized regression coefficient\nmsg.payload = (mlr.predict([3, 3]));\n// [6, 6, 6]\n\nreturn msg;\n\n//https://www.npmjs.com/package/ml-linear-regression","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"MLR","module":"ml-linear-regression"}],"x":350,"y":460,"wires":[["e3efc42859a53485"]]},{"id":"59dd7ae2d05a469c","type":"inject","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-linear-regression","payload":"true","payloadType":"bool","x":170,"y":460,"wires":[["3530b3c70c572fae"]]},{"id":"e3efc42859a53485","type":"debug","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":460,"wires":[]},{"id":"90a9661a8150cd41","type":"function","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"KNN v1","func":"var dataset = [\n    [0, 0, 0],\n    [0, 1, 1],\n    [1, 1, 0],\n    [2, 2, 2],\n    [1, 2, 2],\n    [2, 1, 2]\n];\nvar predictions = [0, 0, 0, 1, 1, 1];\nvar knn = new KNN(dataset, predictions);\n\n\n// var dataset = [[0, 0, 0], [2, 2, 2]];\n\nvar ans = knn.predict(dataset);\n\nmsg.payload=ans;\nreturn msg;\n\n// https://www.npmjs.com/package/ml-knn\n//https://github.com/mljs/knn","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"KNN","module":"ml-knn"}],"x":340,"y":180,"wires":[["cb03402819d9d203"]]},{"id":"795035ec76ba9fa2","type":"inject","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-knn","payload":"true","payloadType":"bool","x":190,"y":180,"wires":[["90a9661a8150cd41"]]},{"id":"cb03402819d9d203","type":"debug","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":180,"wires":[]},{"id":"3f1c257a38fc5d2f","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"brain.js","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"brainjs","payload":"","payloadType":"date","x":790,"y":160,"wires":[["cb827096bc6143f2"]]},{"id":"56c6e21b631c1455","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 8","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":160,"wires":[]},{"id":"cb827096bc6143f2","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"LSTMTimeStep","func":"const net = new brain.recurrent.LSTMTimeStep({\n  inputSize: 2,\n  hiddenLayers: [10],\n  outputSize: 2,\n});\n\n// Same test as previous, but combined on a single set\nconst trainingData = [\n  [\n    [1, 5],\n    [2, 4],\n    [3, 3],\n    [4, 2],\n    [5, 1],\n  ],\n];\n\nnet.train(trainingData, { log: true, errorThresh: 0.09 });\n\nconst closeToFiveAndOne = net.run([\n  [1, 5],\n  [2, 4],\n  [3, 3],\n  [4, 2],\n]);\n\nconsole.log(closeToFiveAndOne);\n\n// now we're cookin' with gas!\nconst forecast = net.forecast(\n  [\n    [1, 5],\n    [2, 4],\n  ],\n  3\n);\n\n// console.log('next 3 predictions', forecast);\nmsg.payload = forecast;\nreturn msg;\n\n// https://github.com/brainjs/brain.js/blob/HEAD/examples/javascript/predict-numbers.js","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"brain","module":"brainjs"}],"x":980,"y":160,"wires":[["56c6e21b631c1455"]]},{"id":"8492468603b308fb","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"Isolation-Forest","func":"let X = [\n  [200, 50],\n  [0.3, 0.1],\n  [0.5, 0.3],\n  [0.2, 0.1],\n  [0.1, 0.1],\n  [0.2, 0.05],\n  [0.3, 0.3],\n  [0.4, 0.2],\n  [0.3, 0.4],\n  [0.1, 0.1],\n  [0.05, 0.1],\n];\nlet anomalyDetector = new IsolationForest();\nanomalyDetector.train(X);\nlet result = anomalyDetector.predict([\n  [200, 300],\n  [0, 0.1],\n  [0.2, 0.1],\n  [0.1, 0.2],\n]);\n\n\n//console.log(result);\n// 0.8138034871711983,0.36863229603385717,0.30237588018462913,0.3277350851756707\n\nmsg.payload = result;\nreturn msg;\n\n//https://www.npmjs.com/package/ml-isolation-forest","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"IsolationForest","module":"ml-isolation-forest"}],"x":980,"y":200,"wires":[["d85142d6d741b85f"]]},{"id":"be9afb066dd5b51a","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-isolation-forest","payload":"true","payloadType":"bool","x":790,"y":200,"wires":[["8492468603b308fb"]]},{"id":"d85142d6d741b85f","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 11","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":200,"wires":[]},{"id":"54fa43481c02103d","type":"comment","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"NOT WORKING! - Need Help","info":"","x":980,"y":100,"wires":[]},{"id":"ab25accd38811033","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"random-forest-classifier","payload":"","payloadType":"date","x":790,"y":240,"wires":[["178899fc56bd8204"]]},{"id":"178899fc56bd8204","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"Random Forest","func":"var data = [\n    {\n        \"length\": 5.1,\n        \"width\": 3.5,\n        \"petal_length\": 1.4,\n        \"petal_width\": 0.2,\n        \"species\": \"setosa\"\n    },\n    {\n        \"length\": 6.5,\n        \"width\": 3,\n        \"petal_length\": 5.2,\n        \"petal_width\": 2,\n        \"species\": \"virginica\"\n    },\n    {\n        \"length\": 6.6,\n        \"width\": 3,\n        \"petal_length\": 4.4,\n        \"petal_width\": 1.4,\n        \"species\": \"versicolor\"\n    }\n];\n\nvar testdata = [{\n    \"length\": 6.3,\n    \"width\": 2.5,\n    \"petal_length\": 5,\n    \"petal_width\": 1.9,\n    //\"species\":\"virginica\"\n},\n{\n    \"length\": 4.7,\n    \"width\": 3.2,\n    \"petal_length\": 1.3,\n    \"petal_width\": 0.2,\n    //\"species\":\"setosa\"\n}\n];\n\nvar rf = new RandomForestClassifier({\n    n_estimators: 10\n});\n\nrf.fit(data, null, \"species\", function (err, trees) {\n    //console.log(JSON.stringify(trees, null, 4));\n    var pred = rf.predict(testdata, trees);\n\n    \n    msg.payload = pred;\n    // pred = [\"virginica\", \"setosa\"]\n});\n\n\nreturn msg;\n\n// https://www.npmjs.com/package/random-forest-classifier","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"fs","module":"fs"},{"var":"RandomForestClassifier","module":"random-forest-classifier"}],"x":980,"y":240,"wires":[["7f20dde4c03b45aa"]]},{"id":"7f20dde4c03b45aa","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 12","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1180,"y":240,"wires":[]},{"id":"1fadcf7775f3e5b3","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"Random Forest #2","func":"const dataset = [\n       [73, 80, 75, 152],\n       [93, 88, 93, 185],\n       [89, 91, 90, 180],\n       [96, 98, 100, 196],\n       [73, 66, 70, 142],\n       [53, 46, 55, 101],\n       [69, 74, 77, 149],\n       [47, 56, 60, 115],\n       [87, 79, 90, 175],\n       [79, 70, 88, 164],\n       [69, 70, 73, 141],\n       [70, 65, 74, 141],\n       [93, 95, 91, 184],\n       [79, 80, 73, 152],\n       [70, 73, 78, 148],\n       [93, 89, 96, 192],\n       [78, 75, 68, 147],\n       [81, 90, 93, 183],\n       [88, 92, 86, 177],\n       [78, 83, 77, 159],\n       [82, 86, 90, 177],\n       [86, 82, 89, 175],\n       [78, 83, 85, 175],\n       [76, 83, 71, 149],\n       [96, 93, 95, 192]\n];\n\nconst trainingSet = new Array(dataset.length);\nconst predictions = new Array(dataset.length);\n\nfor (let i = 0; i < dataset.length; ++i) {\n       trainingSet[i] = dataset[i].slice(0, 3);\n       predictions[i] = dataset[i][3];\n}\n\nconst options = {\n       seed: 3,\n       maxFeatures: 2,\n       replacement: false,\n       nEstimators: 200\n};\n\nconst regression = new RFRegression(options);\nregression.train(trainingSet, predictions);\nconst result = regression.predict(trainingSet);\n\nmsg.payload = result\nreturn msg;\n\n//https://github.com/mljs/random-forest#readme","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"RFRegression","module":"ml-random-forest"}],"x":990,"y":280,"wires":[["fe6b6251d3a39e47"]]},{"id":"e31f1c5e060aa92e","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":790,"y":280,"wires":[["1fadcf7775f3e5b3"]]},{"id":"fe6b6251d3a39e47","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1180,"y":280,"wires":[]},{"id":"0ecd44b3f1c7872b","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"ml-cart","func":"// import { DecisionTreeRegression as DTRegression } from 'ml-cart';\n\nconst x = new Array(100);\nconst y = new Array(100);let val = 0.0;\nfor (let i = 0; i < x.length; ++i) {\n  x[i] = val;\n  y[i] = Math.sin(x[i]);\n  val += 0.01;\n}\n\nconst reg = new DTRegression();\nreg.train(x, y);\nconst estimations = reg.predict(x);\nmsg.payload = estimations;\nreturn msg;\n\n//https://www.npmjs.com/package/ml-cart","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"DTRegression","module":"ml-cart"}],"x":950,"y":320,"wires":[["7ae597bcb008b8b6"]]},{"id":"699f10823e1bba29","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-cart","payload":"","payloadType":"date","x":790,"y":320,"wires":[["0ecd44b3f1c7872b"]]},{"id":"7ae597bcb008b8b6","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 14","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1180,"y":320,"wires":[]},{"id":"1257750dc0020133","type":"function","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"Linear Regression","func":"//import SimpleLinearRegression from 'ml-regression-simple-linear';\n\nconst x = [0.5, 1, 1.5, 2, 2.5];\nconst y = [0, 1, 2, 3, 4];\n\nconst regression = new SimpleLinearRegression(x, y);\n\nregression.slope // 2\nregression.intercept // -1\nregression.coefficients // [-1, 2]\n\nregression.predict(3); // 5\nregression.computeX(3.5); // 2.25\n\nregression.toString(); // 'f(x) = 2 * x - 1'\n\nregression.score(x, y);\n// { r: 1, r2: 1, chi2: 0, rmsd: 0 }\n\nconst json = regression.toJSON();\n// { name: 'simpleLinearRegression', slope: 2, intercept: -1 }\nconst loaded = SimpleLinearRegression.load(json);\nmsg.payload = loaded.predict(5) // 9\nreturn msg;\n\n//https://www.npmjs.com/package/ml-regression-simple-linear","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"SimpleLinearRegression","module":"ml-regression-simple-linear"}],"x":350,"y":500,"wires":[["2951b684c90afad0"]]},{"id":"b69bb22f9380d6d2","type":"inject","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-regression-simple-linear","payload":"","payloadType":"date","x":170,"y":500,"wires":[["1257750dc0020133"]]},{"id":"2951b684c90afad0","type":"debug","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":500,"wires":[]},{"id":"c2f7c74f01a4bb7d","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"Logistic Regression","func":"//const LogisticRegression = require('ml-logistic-regression');\n//const { Matrix } = require('ml-matrix');\n\n// Our training set (X,Y).\nconst X = new Matrix([[0, -1], [1, 0], [1, 1], [1, -1], [2, 0], [2, 1], [2, -1], [3, 2], [0, 4], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4], [1, 10], [1, 12], [2, 10], [2, 11], [2, 14], [3, 11]]);\nconst Y = Matrix.columnVector([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]);\n\n// The test set (Xtest, Ytest).\nconst Xtest = new Matrix([\n    [0, -2],\n    [1, 0.5],\n    [1.5, -1],\n    [1, 2.5],\n    [2, 3.5],\n    [1.5, 4],\n    [1, 10.5],\n    [2.5, 10.5],\n    [2, 11.5],\n]);\nconst Ytest = Matrix.columnVector([0, 0, 0, 1, 1, 1, 2, 2, 2]);\n\n// We will train our model.\nconst logreg = new LogisticRegression({ numSteps: 1000, learningRate: 5e-3 });\nlogreg.train(X, Y);\n\n// We try to predict the test set.\nconst finalResults = logreg.predict(Xtest);\n\n// Now, you can compare finalResults with the Ytest, which is what you wanted to have.\n\nmsg.payload = finalResults;\nreturn msg;\n\n//https://github.com/mljs/logistic-regression#readme","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"LogisticRegression","module":"ml-logistic-regression"},{"var":"Matrix","module":"ml-matrix"}],"x":990,"y":360,"wires":[["a4b12b8fbf370c0d"]]},{"id":"ffc1d6cebe280389","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-logistic-regression","payload":"","payloadType":"date","x":790,"y":360,"wires":[["c2f7c74f01a4bb7d"]]},{"id":"a4b12b8fbf370c0d","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1180,"y":360,"wires":[]},{"id":"1adb2d032b212dc8","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-pca","payload":"","payloadType":"date","x":810,"y":400,"wires":[["c82d2f453fe4efb5"]]},{"id":"c82d2f453fe4efb5","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"PCA","func":"//const { PCA } = require('ml-pca');\n//const dataset = require('ml-dataset-iris').getNumbers();\n\n// dataset is a two-dimensional array where rows represent the samples and columns the features\n\nconst pca = new PCA(dataset);\nconsole.log(pca.getExplainedVariance());\n/*\n[ 0.9246187232017269,\n  0.05306648311706785,\n  0.017102609807929704,\n  0.005212183873275558 ]\n*/\nconst newPoints = [\n  [4.9, 3.2, 1.2, 0.4],\n  [5.4, 3.3, 1.4, 0.9],\n];\n// console.log(pca.predict(newPoints)); // project new points into the PCA space\n\nmsg.payload = pca.predict(newPoints); // project new points into the PCA space\n/*\n[\n  [ -2.830722471866897,\n    0.01139060953209596,\n    0.0030369648815961603,\n    -0.2817812120420965 ],\n  [ -2.308002707614927,\n    -0.3175048770719249,\n    0.059976053412802766,\n    -0.688413413360567 ]]\n*/\n\nreturn msg;\n\n//https://www.npmjs.com/package/ml-pca","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"PCA","module":"ml-pca"},{"var":"dataset","module":"ml-dataset-iris"}],"x":950,"y":400,"wires":[["2ca495b38d7e9f02"]]},{"id":"2ca495b38d7e9f02","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 17","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1180,"y":400,"wires":[]},{"id":"6b24e3535207db2e","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"Hidden Markov Model","func":"\nvar milk = new hmm();\nvar something = ['white', 'bottle'];\nmilk.initialize([something], 2);\n//console.log('The probability that something white in a bottle is milk is ' + (milk.generationProbability(something) * 100) + '%.');\n\nmsg.payload = milk.generationProbability(something);\nreturn msg;\n\n//https://www.npmjs.com/package/HiddenMarkovModel","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"hmm","module":"HiddenMarkovModel"}],"x":1000,"y":440,"wires":[["43de70a3f5e9bb92"]]},{"id":"d75c2dad44d9f2e2","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"HiddenMarkovModel","payload":"","payloadType":"date","x":810,"y":440,"wires":[["6b24e3535207db2e"]]},{"id":"43de70a3f5e9bb92","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 18","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1180,"y":440,"wires":[]},{"id":"511aa4ffaf263a1f","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"xgboost-scorer","payload":"","payloadType":"date","x":810,"y":480,"wires":[["42690fa2c194c670"]]},{"id":"42690fa2c194c670","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"XGBoost","func":"//import Scorer from 'xgboost-scorer';\n\n// Create a scorer using an XGBoost model and (optionally) a feature index\nconst scorer = await Scorer.create('xgboost.model.json', 'feature_index.json');\n\n// Get the score for an instance by passing a mapping of (feature -> value)\nconst score =\n    await scorer.score({\n        featureA: 100,\n        featureB: 0.1,\n        categoricalFeatureC: 1.0\n    })\nconsole.log(score); // E.g., 0.42\n\n\nmsg.payload = score;\n\nreturn msg;\n\n//https://github.com/prvnsmpth/xgboost-scorer\n\n//https://www.npmjs.com/package/xgboost-scorer","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"Scorer","module":"xgboost-scorer"}],"x":960,"y":480,"wires":[["ad7a7db10225d11e"]]},{"id":"ad7a7db10225d11e","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 19","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1200,"y":480,"wires":[]},{"id":"2529f222a8e6f40b","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"SVM WASM","func":"const svm = new SVM();\nawait svm.init()\nconst data = [[-1, -1], [1, 1], [2, 2], [-2, -2]]\nconst label = [-1, 1, 1, -1];\n\nsvm.feedSamples(data, label);\nawait svm.train();\nmsg.payload = svm.predict([3, 3]);\nreturn msg;\n\n//https://www.npmjs.com/package/libsvm-wasm","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"SVM","module":"libsvm-wasm"}],"x":970,"y":520,"wires":[["972e06bf1aaeb612"]]},{"id":"c23b860b438e3a72","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"libsvm-wasm","payload":"true","payloadType":"bool","x":790,"y":520,"wires":[["2529f222a8e6f40b"]]},{"id":"972e06bf1aaeb612","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1140,"y":520,"wires":[]},{"id":"bdd66cd79298a040","type":"function","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"Multivariate Linear Regression","func":"// import MLR from \"ml-regression-multivariate-linear\";\n\nconst x = [\n  [0, 0],\n  [1, 2],\n  [2, 3],\n  [3, 4]\n];\n// Y0 = X0 * 2, Y1 = X1 * 2, Y2 = X0 + X1\nconst y = [\n  [0, 0, 0],\n  [2, 4, 3],\n  [4, 6, 5],\n  [6, 8, 7]\n];\nconst mlr = new MLR(x, y);\nmsg.payload = mlr.predict([3, 3]);\n// [6, 6, 6]\nreturn msg;\n\n// https://github.com/mljs/regression-multivariate-linear ","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"MLR","module":"ml-regression-multivariate-linear"}],"x":330,"y":540,"wires":[["41cfa308b6d362ca"]]},{"id":"cdec698caa3bc993","type":"inject","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-regression-multivariate-linear","payload":"","payloadType":"date","x":130,"y":540,"wires":[["bdd66cd79298a040"]]},{"id":"f07acec55be5622e","type":"comment","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"Confusion Matrix","info":"","x":200,"y":660,"wires":[]},{"id":"251c5d82ca092385","type":"function","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"Confusion Matrix","func":"// import ConfusionMatrix from 'ml-confusion-matrix';\n\nconst trueLabels = [0, 1, 0, 1, 1, 0];\nconst predictedLabels = [1, 1, 1, 1, 0, 0];\n\n// The order of the arguments are important !!!\nconst CM2 = ConfusionMatrix.fromLabels(trueLabels, predictedLabels);\nmsg.payload = CM2.getAccuracy(); // 0.5\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"ConfusionMatrix","module":"ml-confusion-matrix"}],"x":370,"y":700,"wires":[["205bfd0ad53f8c32"]]},{"id":"2177305f18c9d7f9","type":"inject","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-random-fores","payload":"","payloadType":"date","x":190,"y":700,"wires":[["251c5d82ca092385"]]},{"id":"205bfd0ad53f8c32","type":"debug","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"debug 20","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":700,"wires":[]},{"id":"caaf64c7f22651dc","type":"function","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"Random Forest","func":"//import { RandomForestRegression as RFRegression } from 'ml-random-forest';\n\nconst dataset = [\n    [73, 80, 75, 152],\n    [93, 88, 93, 185],\n    [89, 91, 90, 180],\n    [96, 98, 100, 196],\n    [73, 66, 70, 142],\n    [53, 46, 55, 101],\n    [69, 74, 77, 149],\n    [47, 56, 60, 115],\n    [87, 79, 90, 175],\n    [79, 70, 88, 164],\n    [69, 70, 73, 141],\n    [70, 65, 74, 141],\n    [93, 95, 91, 184],\n    [79, 80, 73, 152],\n    [70, 73, 78, 148],\n    [93, 89, 96, 192],\n    [78, 75, 68, 147],\n    [81, 90, 93, 183],\n    [88, 92, 86, 177],\n    [78, 83, 77, 159],\n    [82, 86, 90, 177],\n    [86, 82, 89, 175],\n    [78, 83, 85, 175],\n    [76, 83, 71, 149],\n    [96, 93, 95, 192]\n];\n\nconst trainingSet = new Array(dataset.length);\nconst predictions = new Array(dataset.length);\n\nfor (let i = 0; i < dataset.length; ++i) {\n    trainingSet[i] = dataset[i].slice(0, 3);\n    predictions[i] = dataset[i][3];\n}\n\nconst options = {\n    seed: 3,\n    maxFeatures: 2,\n    replacement: false,\n    nEstimators: 200\n};\n\nconst regression = new RFRegression(options);\nregression.train(trainingSet, predictions);\nconst result = regression.predict(trainingSet);\nmsg.payload = result\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"RFRegression","module":"ml-random-forest"}],"x":980,"y":560,"wires":[["d4dd878441c2322f"]]},{"id":"1e75e6aba1b24649","type":"inject","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-random-fores","payload":"","payloadType":"date","x":790,"y":560,"wires":[["caaf64c7f22651dc"]]},{"id":"d4dd878441c2322f","type":"debug","z":"90ee7c5cf126aba4","g":"a89bc0cef2ffe279","name":"debug 22","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1140,"y":560,"wires":[]},{"id":"d7bb51b35101e96a","type":"function","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"KNN v2","func":"var train_dataset = [\n    [0, 0, 0],\n    [0, 1, 1],\n    [1, 1, 0],\n    [2, 2, 2],\n    [1, 2, 2],\n    [2, 1, 2],\n];\nvar train_labels = [0, 0, 0, 1, 1, 1];\nvar knn = new KNN(train_dataset, train_labels, { k: 2 }); // consider 2 nearest neighbors\n\nvar test_dataset = [\n    [0.9, 0.9, 0.9],\n    [1.1, 1.1, 1.1],\n    [1.1, 1.1, 1.2],\n    [1.2, 1.2, 1.2],\n];\n\nvar ans = knn.predict(test_dataset);\n\nmsg.payload = ans;\n// classification result:\n// ans = [ 0, 0, 1, 1 ]\n// Based on the training data, the first two points of the test dataset are classified as \"0\" (type 0, perhaps),\n// the third and fourth data points are classified as \"1\".\nreturn msg;\n\n//https://github.com/mljs/knn","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"KNN","module":"ml-knn"}],"x":340,"y":220,"wires":[["12e8c4dab2f08e73"]]},{"id":"e88168d52ac07598","type":"inject","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ml-knn","payload":"true","payloadType":"bool","x":190,"y":220,"wires":[["d7bb51b35101e96a"]]},{"id":"12e8c4dab2f08e73","type":"debug","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":220,"wires":[]},{"id":"41cfa308b6d362ca","type":"debug","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"debug 23","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":540,"wires":[]},{"id":"eb25319f0fc18869","type":"comment","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"Supervised learning","info":"","x":530,"y":140,"wires":[]},{"id":"2c83edeceb16c3a8","type":"comment","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"WORKING","info":"","x":340,"y":100,"wires":[],"icon":"node-red/arduino.png"},{"id":"ec7a2eb0108c6b2f","type":"comment","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"Unsupervised learning","info":"","x":520,"y":340,"wires":[]},{"id":"08bb0017370ee0cc","type":"debug","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":380,"wires":[]},{"id":"3b43f0e8320a2f93","type":"function","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"K-means","func":"async function testPCA() {\n\n    let mat = [\n        [40, 50, 60],\n        [50, 70, 60],\n        [80, 70, 90],\n        [50, 60, 80]\n    ]\n    console.log('mat', mat)\n    // => mat [ [ 40, 50, 60 ], [ 50, 70, 60 ], [ 80, 70, 90 ], [ 50, 60, 80 ] ]\n\n    let resMat = await WCluster.PCA(mat, { nCompNIPALS: 2 })\n    msg.payload = (resMat)\n    // => [\n    //     [ 36.76572825085965, 50.81184119955175, 61.992939427698765 ],\n    //     [ 50.520478881706346, 69.86935352609807, 59.679283942385844 ],\n    //     [ 77.39502404588043, 70.65388036857387, 91.60517102143689 ],\n    //     [ 55.318768821553576, 58.66492490577632, 76.7226056084785 ]\n    // ]\n\n}\ntestPCA()\n    .catch((err) => {\n        console.log(err)\n    })\n\n    return msg;\n\n    //https://www.npmjs.com/package/w-cluster","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"WCluster","module":"w-cluster"}],"x":340,"y":380,"wires":[["08bb0017370ee0cc"]]},{"id":"15f021f2170ef627","type":"inject","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"w-cluster","payload":"","payloadType":"date","x":190,"y":380,"wires":[["3b43f0e8320a2f93"]]},{"id":"6bda6c0de06edbfd","type":"comment","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"Regression","info":"","x":550,"y":420,"wires":[]},{"id":"26738e34e35ee051","type":"inject","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"brain.js","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"w-cluster","payload":"","payloadType":"date","x":190,"y":620,"wires":[["e3d599f2156d5ac2"]]},{"id":"e3d599f2156d5ac2","type":"function","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"NeuralNetwork","func":"// provide optional config object (or undefined). Defaults shown.\nconst config = {\n    binaryThresh: 0.5,\n    hiddenLayers: [3], // array of ints for the sizes of the hidden layers in the network\n    activation: 'sigmoid', // supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh'],\n    leakyReluAlpha: 0.01, // supported for activation type 'leaky-relu'\n};\n\n// create a simple feed forward neural network with backpropagation\nconst net = new brain.NeuralNetwork(config);\n\nnet.train([\n    { input: [0, 0], output: [0] },\n    { input: [0, 1], output: [1] },\n    { input: [1, 0], output: [1] },\n    { input: [1, 1], output: [0] },\n]);\n\nconst output = net.run([1, 0]); // [0.987]\nmsg.payload = output;\nreturn msg;\n\n//https://www.npmjs.com/package/brain.js\n\n//https://github.com/brainjs/brain.js#readme","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"brain","module":"brainjs"}],"x":360,"y":620,"wires":[["90adba48e7057924"]]},{"id":"90adba48e7057924","type":"debug","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"debug 9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":620,"wires":[]},{"id":"0ff77769a4c38273","type":"comment","z":"90ee7c5cf126aba4","g":"e0f308659e515f62","name":"ANN","info":"","x":570,"y":580,"wires":[]}]