# How to choose target feature in decision tree classifier node-red node

**URL:** <https://discourse.nodered.org/t/how-to-choose-target-feature-in-decision-tree-classifier-node-red-node/45507>\
**Category:** General\
**Created:** [11 May 2021 18:31 UTC](https://discourse.nodered.org/t/how-to-choose-target-feature-in-decision-tree-classifier-node-red-node/45507 "2021-05-11T18:31:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![usergotaquestion](https://avatars.discourse-cdn.com/v4/letter/u/f9ae1b/32.png) [@usergotaquestion](https://discourse.nodered.org/u/usergotaquestion)\
**Post date:** [11 May 2021 18:31 UTC](https://discourse.nodered.org/t/how-to-choose-target-feature-in-decision-tree-classifier-node-red-node/45507/1 "2021-05-11T18:31:28Z")

</div>

I'm trying to make a classification prediction(although multivariate regression would be better;but there are no regression node, which is a problem for another day). I created the training and testing dataset using the create dataset node. Then i trained the decision tree classifier model but there were no option to choose the target feature like for example setosa,versicolor column in the classic iris dataset. Im having a bunch of number from 20-30 each of which is a catergory(similar to setosa,versicolor but number from 20-30 instead of names) for the classifier. But training was successful. Then i tried to make prediction and **i get some errors:**

1)Traceback (most recent call last):

File "C:\Users\messi.node-red\node\_modules\node-red-contrib-machine-learning-v2\nodes\predictor\predictor.py", line 33, in

1. print(json.dumps(model.predict(features)))

File "C:\Users\messi.node-red\node\_modules\node-red-contrib-machine-learning-v2\nodes\predictor/../../utils\sklw.py", line 28, in predict

1. return self.model.predict(x).tolist()

File "C:\Users\messi\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\tree\_classes.py", line 442, in predict

1. X = self.\_validate\_X\_predict(X, check\_input)

File "C:\Users\messi\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\tree\_classes.py", line 407, in \_validate\_X\_predict

5)self.\_check\_n\_features(X, reset=reset)

File "C:\Users\messi\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\base.py", line 365, in \_check\_n\_features

1. raise ValueError(

ValueError: X has 3 features, but DecisionTreeClassifier is expecting 2 features as input.

**Here are my nodes:**

[{"id":"b9a76546.8bf828","type":"tab","label":"reg\_test","disabled":false,"info":""},{"id":"ac4682ef.6d6b38","type":"load dataset","z":"b9a76546.8bf828","name":"","datasetFolder":"D:\CSE\IOT Domain Analyst\project","datasetName":"W\_Dataset","partition":"train.csv","input":true,"output":true,"x":330,"y":160,"wires":[["44848e97.b977a8"],["4b8d4621.194048"]]},{"id":"479f11d3.282c9","type":"inject","z":"b9a76546.8bf828","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":220,"wires":[["ac4682ef.6d6b38","663f0717.f445c8"]]},{"id":"1ed302cb.f7abed","type":"debug","z":"b9a76546.8bf828","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":80,"wires":},{"id":"4b8d4621.194048","type":"debug","z":"b9a76546.8bf828","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":240,"wires":},{"id":"b87d6960.35de98","type":"predictor","z":"b9a76546.8bf828","name":"","modelPath":"D:\CSE\IOT Domain Analyst\project","modelName":"D\_TREE","x":500,"y":240,"wires":[["44848e97.b977a8"],["4b8d4621.194048"]]},{"id":"663f0717.f445c8","type":"load dataset","z":"b9a76546.8bf828","name":"","datasetFolder":"D:\CSE\IOT Domain Analyst\project","datasetName":"W\_Dataset","partition":"test.csv","input":true,"output":true,"x":330,"y":280,"wires":[["b87d6960.35de98"],["4b8d4621.194048"]]},{"id":"44848e97.b977a8","type":"assessment","z":"b9a76546.8bf828","name":"","score":"accuracy\_score","x":550,"y":80,"wires":[["1ed302cb.f7abed"],["4b8d4621.194048"]]}]

**TRAIN CSV:**  
26,79,25  
24,86,18  
23,91,18  
22,94,19  
22,94,19  
21,94,19  
21,93,19  
22,88,19  
26,74,21  
28,63,22  
30,51,23  
31,50,24  
30,52,25  
30,53,26  
30,54,27  
29,57,28  
28,60,26  
29,60,25  
28,63,25  
27,66,24  
27,67,23  
27,68,23  
26,70,22  
26,72,22  
26,74,22  
26,75,22  
25,77,23  
25,80,22  
24,83,22  
23,85,22  
23,86,22  
25,77,22  
27,67,24  
29,57,26  
30,52,28  
31,49,28  
31,47,28  
31,47,28  
31,48,28  
30,49,28  
30,50,28  
29,53,27  
28,57,26  
27,58,25  
27,59,25  
27,62,25  
26,64,25  
26,65,25  
26,66,25  
26,66,25  
25,68,24  
25,70,24  
24,74,24  
23,77,24  
22,79,23  
24,72,23  
27,61,23  
29,53,24  
30,49,26  
31,48,28  
31,47,28  
31,48,28  
31,48,28  
30,50,27  
30,54,27  
28,58,27  
27,62,27  
27,64,27  
27,64,27  
26,65,27  
26,67,26  
26,69,26  
26,71,26  
25,74,21  
24,77,22  
23,82,22  
22,86,22  
21,86,22  
21,82,22  
23,72,22  
26,62,24  
29,54,24  
31,48,26  
31,47,26  
29,54,26  
30,52,28  
31,50,28  
30,56,28  
29,58,26  
28,61,26  
27,65,25  
27,67,25  
27,70,25  
26,72,25  
26,73,26  
26,74,25  
26,74,25  
25,77,25  
25,81,25  
24,85,24  
23,90,24  
23,89,24  
22,89,24  
24,80,23  
27,69,24  
29,60,24  
30,53,28  
31,51,27  
32,50,27  
32,49,28  
31,48,27  
31,50,27  
30,53,28  
29,57,26  
28,63,26  
27,64,27  
27,64,27  
27,64,25  
27,67,26  
26,68,25  
26,70,25  
26,72,25  
25,75,24  
25,78,24  
23,83,24  
22,86,23  
22,85,23  
24,75,23  
27,65,24  
29,56,26  
31,49,27  
32,47,27  
32,48,27  
32,47,27  
31,47,27  
31,51,27  
30,56,27  
29,60,26  
28,63,26  
27,65,26  
27,66,26  
27,67,26  
27,70,26  
26,73,26  
26,75,26  
26,76,25  
25,77,25  
25,79,26  
24,82,25

**TEST CSV:**  
24,83,26  
24,80,25  
26,72,25  
28,65,25  
30,56,26  
31,53,25  
32,51,26  
32,51,27  
31,53,28  
31,54,28  
30,55,28  
30,58,28  
29,63,28  
28,67,28  
27,68,27  
27,70,27  
27,71,27  
27,72,27  
26,74,26  
26,75,26  
26,78,26  
25,81,25  
24,86,25  
24,86,25  
24,86,26  
24,85,26  
26,80,26  
27,73,27  
29,63,27  
31,51,27  
32,49,27  
33,49,27  
32,51,27  
32,52,27  
31,52,27  
30,58,28  
29,64,28  
28,70,28  
27,73,27  
27,75,26  
26,78,26  
26,78,25

I WANT THE LAST COLUMN TO BE THE TARGET

---

<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:** [10 July 2021 18:31 UTC](https://discourse.nodered.org/t/how-to-choose-target-feature-in-decision-tree-classifier-node-red-node/45507/2 "2021-07-10T18:31:35Z")

</div>

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