Building a Decision Tree in Python from Postgres data - Gary Sieling
decision-treepythonpostgresscikit-learnclassification
Abstraction: Tutorial building scikit-learn decision tree from PostgreSQL relational data
Key points:
- Uses UCI adult income dataset (20-year-old, predicts income > or < $50K from demographic features)
- Data loaded from Postgres via SQLAlchemy + pg8000 driver; text labels must be mapped to integers for sklearn
- Decision tree built in three lines: import tree, DecisionTreeRegressor(), clf.fit(trn, trn_v)
- DecisionTreeClassifier achieved 78% accuracy; DecisionTreeRegressor achieved 79% on hold-out test set
- Reference accuracy from paper: C4.5 at 15.54% error, FSS Naive Bayes at 14.05% error (best in original paper)
- Decision trees can be thousands of rules deep on real data, making visualization impractical except for simple cases
Connections: Scikit Learn · Postgresql · Decision Trees · Supervised Learning · Machine Learning
Source: http://www.garysieling.com/blog/building-decision-tree-python-postgres-data