decision-tree

Passing categorical data to Sklearn Decision Tree

Passing categorical data to Sklearn Decision Tree Question: There are several posts about how to encode categorical data to Sklearn Decision trees, but from Sklearn documentation, we got these Some advantages of decision trees are: (…) Able to handle both numerical and categorical data. Other techniques are usually specialized in analyzing datasets that have only …

Total answers: 8

How to balance classification using DecisionTreeClassifier?

How to balance classification using DecisionTreeClassifier? Question: I have a data set where the classes are unbalanced. The classes are either 0, 1 or 2. How can I calculate the prediction error for each class and then re-balance weights accordingly in scikit-learn? Asked By: RoyaumeIX || Source Answers: If you want to fully balance (treat …

Total answers: 3

How do you access tree depth in Python's scikit-learn?

How do you access tree depth in Python's scikit-learn? Question: I’m using scikit-learn to create a Random Forest. However, I want to find the individual depths of each tree. It seems like a simple attribute to have but according to the documentation, (http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html) there is no way of accessing it. If this isn’t possible, is …

Total answers: 1

Using GridSearchCV with AdaBoost and DecisionTreeClassifier

Using GridSearchCV with AdaBoost and DecisionTreeClassifier Question: I am attempting to tune an AdaBoost Classifier (“ABT”) using a DecisionTreeClassifier (“DTC”) as the base_estimator. I would like to tune both ABT and DTC parameters simultaneously, but am not sure how to accomplish this – pipeline shouldn’t work, as I am not “piping” the output of DTC …

Total answers: 2

Python, PyDot and DecisionTree

Python, PyDot and DecisionTree Question: I’m trying to visualize my DecisionTree, but getting the error The code is: X = [i[1:] for i in dataset]#attribute y = [i[0] for i in dataset] clf = tree.DecisionTreeClassifier() dot_data = StringIO() tree.export_graphviz(clf.fit(train_X, train_y), out_file=dot_data) graph = pydot.graph_from_dot_data(dot_data.getvalue()) graph.write_pdf(“tree.pdf”) And the error is Traceback (most recent call last): if …

Total answers: 3

Visualizing decision tree in scikit-learn

Visualizing decision tree in scikit-learn Question: I am trying to design a simple Decision Tree using scikit-learn in Python (I am using Anaconda’s Ipython Notebook with Python 2.7.3 on Windows OS) and visualize it as follows: from pandas import read_csv, DataFrame from sklearn import tree from os import system data = read_csv(‘D:/training.csv’) Y = data.Y …

Total answers: 11

how to explain the decision tree from scikit-learn

how to explain the decision tree from scikit-learn Question: I have two problems with understanding the result of decision tree from scikit-learn. For example, this is one of my decision trees: My question is that how I can use the tree? The first question is that: if a sample satisfied the condition, then it goes …

Total answers: 4

How to extract the decision rules from scikit-learn decision-tree?

How to extract the decision rules from scikit-learn decision-tree? Question: Can I extract the underlying decision-rules (or ‘decision paths’) from a trained tree in a decision tree as a textual list? Something like: if A>0.4 then if B<0.2 then if C>0.8 then class=’X’ Asked By: Dror Hilman || Source Answers: from StringIO import StringIO out …

Total answers: 25

How do I find which attributes my tree splits on, when using scikit-learn?

How do I find which attributes my tree splits on, when using scikit-learn? Question: I have been exploring scikit-learn, making decision trees with both entropy and gini splitting criteria, and exploring the differences. My question, is how can I “open the hood” and find out exactly which attributes the trees are splitting on at each …

Total answers: 3