2
$\begingroup$

I'm building a decision tree and would like to separate (for example) the elements that are in class 0 from those in classes 1 and 2, case in point:

df = pd.DataFrame(np.random.randn(500,2),columns=list('AB'))
cdf = pd.DataFrame(columns=['C'])
cdf = pd.concat([cdf,pd.DataFrame(np.random.randint(0,3, size=500), columns=['C'])])
#df=pd.concat([df,cdf], axis=1)
(X_train, X_test, y_train, y_test) = train_test_split(df,cdf,test_size=0.30)
y_train=y_train.astype('int')
classifier = DecisionTreeClassifier(criterion='entropy',max_depth = 2)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)

C represents the class of an element,A and B are two variables that define the element, how can I build a tree that instead of dividing results into C=0, C=1 or C=2 divides them into C=0 and C!=0?

$\endgroup$
2
$\begingroup$

I don't think that is possible with a decision tree, unless there is some measure of confidence that you can use as a threshold.

I ran into the same problem with the ID3 algorithm. It assigns classes, but you only have the resulting class without any confidence or probability attached.

One possible solution could be to add a number of counter examples as a second (dummy, catch-all) class; if the elements of C = 0 are reasonably tightly clustered and your counter examples for C != 0 cover the remaining problem space, then that might work.

$\endgroup$

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.