A custom implementation of decision tree classifier.
Project description
Decision Tree Implementation from Scratch
Overview
This package provides a Python implementation of a decision tree algorithm from scratch, along with training and evaluation utilities. This lightweight implementation has performance comparable to scikit-learn's implementation.
Files
- DecisionTree.py: Contains the core classes and functions for building and using the decision tree model.
- utils.py: Provides helper functions for loading datasets, splitting data, calculating evaluation metrics, and comparing custom and scikit-learn implementations.
Key Features
- Custom implementation of a decision tree algorithm.
- Supports both Gini impurity and entropy criteria for splitting.
- Options to control maximum depth and minimum samples for splitting.
- Functions for loading and processing various inbuilt datasets.
- Comparison with scikit-learn's DecisionTreeClassifier in terms of accuracy, precision, recall, F1-score, time taken, and memory usage.
Usage
Make sure the labels are numeric(Use label encoder).
from decisiontree_lite.decisiontree import DecisionTree
from decisiontree_lite.utils import load_data, train_test, model_metrics
# You can use one of inbuilt datasets('iris', 'digits', 'breast_cancer', 'wine') or an external dataset of your choice
X, y = load_data('iris')
# Perform test train split
test_split_size = 0.3
X_train, X_test, y_train, y_test = train_test(X, y, test_split_size)
clf = DecisionTree()
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
accuracy, precision, recall, f1score = model_metrics(y_test, y_pred)
print("Accuracy: {},\nPrecision: {},\nRecall: {},\nF1-score: {}".format(accuracy, precision, recall, f1score))
Customization
Adjust hyperparameters like max_depth, min_samples_split, and criteria in the DecisionTree to tune the model.
- max_depth: The maximum depth of the tree [1, 2, 4, 8, 16, 32, 64, 100].
- min_samples_split: The minimum number of samples required to split an internal node [2, 50, 100].
- criteria: To split based on gini or entropy impurity ['gini', 'entropy'].
clf = DecisionTree(max_depth = maxDepth, min_samples_split = minSplit, criteria = impCriteria)
Additional Notes
- The code is structured for clarity and modularity.
- Comments are included to explain key concepts and steps.
- Feel free to contribute to this project or use it for your own learning and experimentation!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file decisiontree_lite-0.0.2.tar.gz.
File metadata
- Download URL: decisiontree_lite-0.0.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6704f28bfa282c7d38540ed09ac6c9128de9b9eed687aaa7ddc5166d284c00c
|
|
| MD5 |
4cc29510aed47be0205b15caf18606c3
|
|
| BLAKE2b-256 |
603991b97c49318dad8380e63fb1328beba0b4b86bf9a1f247030e458a23bc14
|
File details
Details for the file decisiontree_lite-0.0.2-py3-none-any.whl.
File metadata
- Download URL: decisiontree_lite-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bef8cc4b524f4659be9f7ddf0095e6424361cef903796438b40ab66dca06f32
|
|
| MD5 |
7cf6b2b18c3d01eb422ebd65bd0cf551
|
|
| BLAKE2b-256 |
5db784b6af4d782f1364741e1947e7536d3508337a949185b90bd11122289ef4
|