Youâre on the right track here! You just need to address a little quirk of JavaScript datatypes, and reformat the data set a little.
The reason the regression node is not producing output is because it never receives the arrays â if you check the debug node youâll see that msg.payload
is still the timestamp that is initially injected. This is an integer, which does not support properties like payload.x
and payload.y
unless you redefine it as an object.
No worries though, itâs an easy fix: msg.payload = {};
sets the payload to be a new, empty object. After doing this youâre free to set properties and youâll see them appear in the debug.
With that fixed, the data just needs to be formatted in a way that the regression node expects. The node info tab says that if x and y properties both contain values, then those values are saved as a point into the data set. The key here is that singluar âa pointâ â this means that both properties are only used for streaming in a data set one point at a time.
In order to put a whole data set in at once, use JUST the x input property, where you have each element be part of your [x,y] data set.
To see what theyâre talking about, check out this flow below, it can use either the numbers you set in the function node, or read injected values directly. Also note that it will produce a straight line due to [3,3] and [2,2] being duplicate data in this set.
[{"id":"58e64c95.45b774","type":"tab","label":"Regression","disabled":false,"info":""},{"id":"336398a4.3c51c8","type":"function","z":"58e64c95.45b774","name":"array of numbers","func":"x =[[1,1],\n [2,2],\n [3,3],\n [4,4],\n [3,3],\n [2,2]];\n\nmsg.payload = {}; \nmsg.payload.x = x;\n\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":180,"wires":[["2c840963.7faf96","2044a945.c20b16"]]},{"id":"aeb1c6d5.357c18","type":"inject","z":"58e64c95.45b774","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":180,"wires":[["336398a4.3c51c8"]]},{"id":"2c840963.7faf96","type":"regression","z":"58e64c95.45b774","name":"","dataSetSize":0,"regressionType":"polynomial","polynomialOrder":"3","precision":"5","xInputField":"payload.x","xInputFieldType":"msg","yInputField":"payload.y","yInputFieldType":"msg","yOutputField":"payload.y","yOutputFieldType":"msg","functionOutputField":"Function","functionOutputFieldType":"msg","resultOnly":false,"x":570,"y":180,"wires":[["64615ed1.df8fd"]]},{"id":"2044a945.c20b16","type":"debug","z":"58e64c95.45b774","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":550,"y":240,"wires":[]},{"id":"64615ed1.df8fd","type":"debug","z":"58e64c95.45b774","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":730,"y":180,"wires":[]},{"id":"f9a5f8e9.e6e1f8","type":"inject","z":"58e64c95.45b774","name":"","topic":"","payload":"{\"x\":5}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":60,"wires":[["2c840963.7faf96"]]},{"id":"b552bb3c.3cc9a8","type":"inject","z":"58e64c95.45b774","name":"","topic":"","payload":"{\"x\":[[1,1],[2,2],[3,3],[4,4],[3,3],[2,2]]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":120,"wires":[["2c840963.7faf96"]]},{"id":"9332529.30173b","type":"comment","z":"58e64c95.45b774","name":"inject enitre JSON array","info":"","x":180,"y":120,"wires":[]},{"id":"c542165c.909c08","type":"comment","z":"58e64c95.45b774","name":"calculate point at x=5","info":"","x":183,"y":60,"wires":[]}]