# Regression node - x(time) format

**URL:** <https://discourse.nodered.org/t/regression-node-x-time-format/53614>\
**Category:** General\
**Created:** [12 November 2021 06:43 UTC](https://discourse.nodered.org/t/regression-node-x-time-format/53614 "2021-11-12T06:43:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [12 November 2021 06:43 UTC](https://discourse.nodered.org/t/regression-node-x-time-format/53614/1 "2021-11-12T06:43:45Z")

</div>

[exporttest3.txt](https://discourse.nodered.org/uploads/short-url/cRBSZq3H3mLjTTvIHSBj5336Brc.txt) (2.5 MB)  
Hi there,  
I am trying to use the node-red-contribution-regression node.  
My x values are date time coming from a flow.  
In which format should I feed the data/time to the regression node?  
At present my date time format is 2021-09-24 18:01:04.919  
But if I use it in such format, I keep getting y=0x+27.89

I noted that passing only the time (18:01:04.919) the regression node is working but since my data includes also year-month-day, I need to pass also this part. At least month-day in addition to the time.  
Another unexpected thing I am experiencing is that such node will start outputting NaN values for Y as soon as a couple of hundred values are computed and the formula starts compiling. I have 36000 points to evaluate. I did try to set the data set size to 36000 but the behaviour doesn't change.

Any hint?

```auto
[
    {
        "id": "d3941b648342c52c",
        "type": "inject",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 280,
        "y": 200,
        "wires": [
            [
                "7b997a168c5e6c62"
            ]
        ]
    },
    {
        "id": "7b997a168c5e6c62",
        "type": "file in",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "filename": "/Users/felicemassaro/Downloads/exporttest3.txt",
        "format": "lines",
        "chunk": false,
        "sendError": false,
        "encoding": "utf8",
        "allProps": false,
        "x": 580,
        "y": 200,
        "wires": [
            [
                "00e59343511ae655"
            ]
        ]
    },
    {
        "id": "db9f3a750ab25d30",
        "type": "function",
        "z": "2b15a36f0d2c0957",
        "name": "Unpack voltage",
        "func": "var output= msg.payload.split(\",\");\nvar voltage=parseFloat(output[2]).toFixed(3);\nvar msg3={payload : voltage};\n\n\n\nreturn msg3;\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 280,
        "wires": [
            [
                "36951e3318a37c7f"
            ]
        ]
    },
    {
        "id": "36951e3318a37c7f",
        "type": "change",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "voltage",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 540,
        "y": 280,
        "wires": [
            [
                "f478dc20e8fbe695"
            ]
        ]
    },
    {
        "id": "cd5274eb82f2c104",
        "type": "link out",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "mode": "link",
        "links": [
            "3c86964fec64c7e3",
            "830d288b2f7bebe7",
            "77731fbfda666688"
        ],
        "x": 975,
        "y": 200,
        "wires": []
    },
    {
        "id": "3c86964fec64c7e3",
        "type": "link in",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "links": [
            "cd5274eb82f2c104"
        ],
        "x": 235,
        "y": 280,
        "wires": [
            [
                "db9f3a750ab25d30"
            ]
        ]
    },
    {
        "id": "41a80d8331729fb4",
        "type": "function",
        "z": "2b15a36f0d2c0957",
        "name": "Unpack time",
        "func": "var output= msg.payload.split(\",\");\nvar time=(output[1]);\nvar msg2={payload : time};\nreturn msg2;\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 360,
        "wires": [
            [
                "032e8dd084339dad"
            ]
        ]
    },
    {
        "id": "77731fbfda666688",
        "type": "link in",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "links": [
            "cd5274eb82f2c104"
        ],
        "x": 235,
        "y": 360,
        "wires": [
            [
                "41a80d8331729fb4"
            ]
        ]
    },
    {
        "id": "032e8dd084339dad",
        "type": "change",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$moment(payload).format('HH:mm:ss.SSS')",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "time",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 520,
        "y": 360,
        "wires": [
            [
                "f478dc20e8fbe695"
            ]
        ]
    },
    {
        "id": "00a67fe38392dfc2",
        "type": "regression",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "dataSetSize": "0",
        "regressionType": "polynomial",
        "polynomialOrder": "2",
        "precision": "4",
        "xInputField": "payload.x",
        "xInputFieldType": "msg",
        "yInputField": "payload.y",
        "yInputFieldType": "msg",
        "yOutputField": "payload.y",
        "yOutputFieldType": "msg",
        "functionOutputField": "P",
        "functionOutputFieldType": "msg",
        "resultOnly": false,
        "x": 1070,
        "y": 320,
        "wires": [
            [
                "40096f992a4d8439"
            ]
        ]
    },
    {
        "id": "40096f992a4d8439",
        "type": "debug",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1250,
        "y": 320,
        "wires": []
    },
    {
        "id": "f478dc20e8fbe695",
        "type": "join",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 710,
        "y": 320,
        "wires": [
            [
                "33ece8d92bd59b5e"
            ]
        ]
    },
    {
        "id": "33ece8d92bd59b5e",
        "type": "function",
        "z": "2b15a36f0d2c0957",
        "name": "sample formatting",
        "func": "msg.payload = {x: msg.payload.time, y: msg.payload.voltage}\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 870,
        "y": 320,
        "wires": [
            [
                "00a67fe38392dfc2"
            ]
        ]
    },
    {
        "id": "250f1e1742af6cce",
        "type": "change",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "1",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 620,
        "y": 100,
        "wires": [
            [
                "00e59343511ae655"
            ]
        ]
    },
    {
        "id": "f9f07b83b576dbc9",
        "type": "inject",
        "z": "2b15a36f0d2c0957",
        "name": "Reset",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 410,
        "y": 100,
        "wires": [
            [
                "250f1e1742af6cce"
            ]
        ]
    },
    {
        "id": "00e59343511ae655",
        "type": "delay",
        "z": "2b15a36f0d2c0957",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "20",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 860,
        "y": 200,
        "wires": [
            [
                "cd5274eb82f2c104"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 November 2021 09:34 UTC](https://discourse.nodered.org/t/regression-node-x-time-format/53614/2 "2021-11-12T09:34:35Z")

</div>

Try converting the date/time to valid ISO format. So something like  
`2021-11-12T07:41:53+00:00`  
where the +00:00 on the end is the timezone offset.

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [12 November 2021 09:37 UTC](https://discourse.nodered.org/t/regression-node-x-time-format/53614/3 "2021-11-12T09:37:38Z")

</div>

Thanks Colin, I am busy trying that but meanwhile I discovered another major thing I do not understand. I have updated my post and also given the data set as attachment. Just in case someone likes to test it.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 November 2021 10:00 UTC](https://discourse.nodered.org/t/regression-node-x-time-format/53614/4 "2021-11-12T10:00:34Z")

</div>

> [@FeliceM](#):
>
> I discovered another major problem

Are you sure it is the amount of data and not a bad sample in there somewhere?  
I suggest that you find the smallest set of data that fails, not thousands of lines, and then post an issue on the node's github page.

If you do that post a link to the issue here for anyone that finds the thread.

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [12 November 2021 10:06 UTC](https://discourse.nodered.org/t/regression-node-x-time-format/53614/5 "2021-11-12T10:06:13Z")

</div>

Will do. However if I import the data in excel, no issues there. I will double check. Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 January 2022 10:07 UTC](https://discourse.nodered.org/t/regression-node-x-time-format/53614/6 "2022-01-11T10:07:05Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
