On GitHub, serengil/decision-trees-for-ml has picked up 70 stars, AI Tools, Jupyter Notebook. Building Decision Trees From Scratch In Python
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Disclaimer: This repository is a sketchbook learning the background of decision tree algorithms. It is neither clean nor readable. Please direct yourself to Chefboost repository to have clean one.
This is the repository of Decision Trees for Machine Learning online course published on Udemy. In this course, the following algorithms will be covered. All project is going to be developed on Python (3.6.4), and neither out-of-the-box library nor framework will be used to build decision trees.
1- ID3
2- C4.5
3- CART (Classification And Regression Trees)
4- Regression Trees (CART for regression)
5- Random Forest
6- Gradient Boosting Decision Trees for Regression
7- Gradient Boosting Decision Trees for Classification
8- Adaboost
Updates
To keep yourself up-to-date you might check posts in my blog about decision trees
Example Usage
Here is a step-by-step example of how to run the decision tree script:
Install dependencies:
pip install -r requirements.txt
Run the main script:
python python/decision.py
Sample input:
The script uses the dataset in dataset/golf.txt by default. You can change the dataset by editing the df = pd.read_csv(...) line in python/decision.py.
Sample output:
After running the script, a file named rules.py will be generated in the python/ directory. This file contains the decision rules as a Python function. You will also see console output similar to:
C4.5 tree is going to be built...
finished in 0.02 seconds
Example of generated rule (in python/rules.py):
def findDecision(obj):
if obj[0] == 'Overcast':
return 'Yes'
if obj[0] == 'Rain':
if obj[3] == 'Weak':
return 'Yes'
if obj[3] == 'Strong':
return 'No'
if obj[0] == 'Sunny':
if obj[2] == 'High':
return 'No'
if obj[2] == 'Normal':
return 'Yes'
Changing the algorithm or dataset:
Edit the variables at the top of python/decision.py to select a different algorithm or dataset.
Output Files and Results
Generated Files
When you run the decision tree script, it generates Python files containing the decision rules. The exact filename depends on the algorithm and settings used:
Standard decision tree:rules.py
Random Forest:rule_0.py, rule_1.py, rule_2.py, etc. (one file per tree)
Gradient Boosting:rules0.py, rules1.py, rules2.py, etc. (one file per iteration)
Adaboost:rules_0.py, rules_1.py, rules_2.py, etc. (one file per round)
Understanding the Output
Decision Rules Format
The generated files contain a Python function called findDecision(obj) that implements the decision tree as a series of if-else statements. For example:
def findDecision(obj):
if obj[0] == 'Sunny':
if obj[2] == 'High':
return 'No'
if obj[2] == 'Normal':
return 'Yes'
if obj[0] == 'Rain':
if obj[3] == 'Weak':
return 'Yes'
if obj[3] == 'Strong':
return 'No'
if obj[0] == 'Overcast':
return 'Yes'
How to Use the Generated Rules
Import the rules file:
import rules # or whatever the generated filename is
Make predictions:
# Create a feature vector (in the same order as your dataset columns)
features = ['Sunny', 'Hot', 'High', 'Weak'] # Example for golf dataset
# Get prediction
prediction = rules.findDecision(features)
print(f"Prediction: {prediction}")
Feature Vector Format
The obj parameter in findDecision(obj) is a list where each element corresponds to a feature column in your dataset, in the same order:
obj[0] = First feature column
obj[1] = Second feature column
obj[2] = Third feature column
And so on...
Example for the golf dataset:
obj[0] = Outlook (Sunny, Overcast, Rain)
obj[1] = Temperature (Hot, Mild, Cool)
obj[2] = Humidity (High, Normal)
obj[3] = Wind (Weak, Strong)
Console Output
When you run the script, you'll see output like:
C4.5 tree is going to be built...
finished in 0.022043228149414062 seconds
This shows:
Which algorithm was used
How long the tree building process took
Multiple Output Files
For ensemble methods (Random Forest, Gradient Boosting, Adaboost), multiple rule files are generated. Each file represents one tree or iteration in the ensemble. To use these:
Random Forest: Use all generated files and take a majority vote
Gradient Boosting: Use files sequentially, each building on the previous
Adaboost: Use all files with their respective weights
Troubleshooting
No output files generated: Check that dump_to_console = False in the script
Wrong predictions: Ensure your feature vector matches the dataset column order
Import errors: Make sure the generated rules file is in your Python path
Running with Command-Line Arguments
You can now configure the script without editing the code by using command-line arguments:
python python/decision.py [OPTIONS]
Available options:
--algorithm (ID3, C4.5, CART, Regression) — Algorithm to use (default: C4.5)
--dataset — Path to dataset file (default: dataset/golf.txt)
--random-forest — Enable Random Forest
--num-trees — Number of trees for Random Forest (default: 3)
--multitasking — Enable multitasking for Random Forest
--adaboost — Enable Adaboost
--gradient-boosting — Enable Gradient Boosting
--epochs — Number of epochs for boosting (default: 10)
--learning-rate — Learning rate for boosting (default: 1)
--dump-to-console — Print rules to console instead of file
How does serengil/decision-trees-for-ml compare to other AI Tools projects?
serengil/decision-trees-for-ml is tracked by TopGit in the AI Tools category, with 70 GitHub stars and written in Jupyter Notebook. Browse the AI Tools topic page on TopGit to compare it against similar projects by stars and activity.
Is serengil/decision-trees-for-ml open source?
Yes — serengil/decision-trees-for-ml ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/serengil/decision-trees-for-ml.
What else is in the AI Tools space?
serengil/decision-trees-for-ml is tracked by TopGit under the AI Tools category, alongside 15 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What is serengil/decision-trees-for-ml?
serengil/decision-trees-for-ml (serengil/decision-trees-for-ml) is a Jupyter Notebook project on GitHub. From the project's own README: Building Decision Trees From Scratch In Python
Where do I read more about serengil/decision-trees-for-ml?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/serengil/decision-trees-for-ml is the definitive source.
Why is serengil/decision-trees-for-ml categorized under AI Tools?
TopGit places serengil/decision-trees-for-ml in the AI Tools category based on its GitHub topics and description (tagged: "adaboost", "bagging", "boosting"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Still deciding about decision-trees-for-ml?
One click hands the question to an AI along with this page — see what it says about decision-trees-for-ml.