4
$\begingroup$

I am learning my way through this, so please be easy on me if you find any mistakes, I could really use a professional opinion here. Thx.

I am trying to model a Decision Tree Classifier as part of an ensemble (soft voting system). The problem is that I have the categorical features already converted to Integer values (i.e. if blood pressure is within the medium range, then blood pressure =2 in the dataset).

The categories for the feature variables are as follows

feature#1 (total cholesterol) = 1, 2, 3

feature#2 (Systolic Blood Pressure) = 1, 2, 3

feature#3 (diastolic Blood Pressure) = 1, 2, 3

feature#4 (smoking rate) = 1, 2, 3

The target/class variable (stroke) = 1, 2 (yes and no, respectively).

The problem is that when I draw the DT (please check the picture), I expect to get a splitting decision where a certain feature equals one of the above-mentioned values (i.e. 1, 2, 3). However, it is giving me other values like 1.5, 0.5, etc.,

I have included the code and a sample dataset for anyone who can help me out. btw, I need to keep the current dataset in the number format as I am using it in conjunction with other classifiers for the soft voting classifier.

Here is the dataset and this is the code for reference, I am using Spyder with Python 3.7 enter image description here

| improve this question | | | | |
$\endgroup$
2
$\begingroup$

Its all ok.

Exactly because your values are between 1 and 2 does he chooses 1.5. In other words trees will select 1 and 2 as values (integers not real numbers) but 1.5 is there as cut-off point between these classes.

| improve this answer | | | | |
$\endgroup$
  • 1
    $\begingroup$ thx for the reply, Please note that the X[1] refers to the second feature variable, not the class variable, the class(target) is labeled with Y and it is hidden here as the slit is done according to the values of the features. I think this will stay the same even if I change the range of the classes to be 0,1 instead of 1,2 . Will try though and see. $\endgroup$ – a_new_moody Dec 22 '19 at 19:14
  • $\begingroup$ I know, you wont see Y in this tree in any case $\endgroup$ – Noah Weber Dec 22 '19 at 19:17
  • 1
    $\begingroup$ So u mean that it is working? and I have no problem at all? $\endgroup$ – a_new_moody Dec 22 '19 at 19:20
  • 1
    $\begingroup$ Yes, that's what I meant $\endgroup$ – Noah Weber Dec 22 '19 at 20:11
0
$\begingroup$

You don't need to do anything with input variables and convert the output to one hot encoded.

Atleast don't do ordinal encoding for the output.

| improve this answer | | | | |
$\endgroup$
  • $\begingroup$ But shouldn't I use ordinal encoding for categorical features? $\endgroup$ – a_new_moody Jan 6 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.