Answers.Body: <p>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.</p>
  
  <p>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.</p>
  
  <p>One possible solution could be to add a number of counter examples as a second (dummy, catch-all) class; if the elements of <code>C = 0</code> are reasonably tightly clustered and your counter examples for <code>C != 0</code> cover the remaining problem space, then that might work.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-08T15:12:33.963Z
Answers.LastActivityDate: 2018-06-08T15:12:33.963Z
Answers.UserDisplayName: Oliver Mason
Body: <p>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:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p><code>C</code> represents the class of an element,<code>A</code> and <code>B</code> are two variables that define the element, how can I build a tree that instead of dividing results into <code>C=0</code>, <code>C=1</code> or <code>C=2</code> divides them into <code>C=0</code> and <code>C!=0</code>?</p>
  
Tags: <classification><decision-trees>
Title: Decision tree: more than 2 classes, how to represent elements that are in a class vs ones that aren't?
UserDisplayName: Jessica Chambers
ThreadText: # Decision tree: more than 2 classes, how to represent elements that are in a class vs ones that aren't?
  
  (Asked by: username_0 on 2018-06-08)
  
  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?
  
  **Tags:** classification, decision-trees
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-08. Score: 3
  
  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.
  
  
  ---
  
  