Train a decision tree using the C4.5 algorithm by Quinlan
Project description
C4.5 Decision Tree
Implementation of the Quinlan's algorithm to train a decision tree and make inference.
Installation
pip install c4dot5-decision-tree
Usage
To train a decision tree classifier, import the class DecisionTreeClassifier and call the .fit() method. The training dataset must be a pandas DataFrame with a column named target to identify the target classes of the classification.
import pandas as pd
from c4dot5.DecisionTreeClassifier import DecisionTreeClassifier
training_dataset = pd.read_csv("https://raw.githubusercontent.com/piepor/C4.5-Decision-Trees/main/src/data_example/training_dataset.csv")
attributes_map = {
"Outlook": "categorical", "Humidity": "continuous",
"Windy": "boolean", "Temperature": "continuous"}
decision_tree = DecisionTreeClassifier(attributes_map)
decision_tree.fit(training_dataset)
To make predictions, simply use the .predict() method
data_input = pd.DataFrame.from_dict({
"Outlook": ["sunny"], "Temperature": [65], "Humidity": [90], "Windy": [False]})
prediction = decision_tree.predict(data_input)
print(prediction)
To visualize the decision tree use method .view(). It will show the tree and save in a folder (default to './figures')
decision_tree.view(folder_name='figures', title='Quinlan-Tree')
To extract the splitting rules of the decision tree use the method .get_rules()
rules = decision_tree.get_rules()
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 c4dot5-decision-tree-1.2.1.tar.gz.
File metadata
- Download URL: c4dot5-decision-tree-1.2.1.tar.gz
- Upload date:
- Size: 42.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2de737a1163024835aef15c1547e44e5162aa14b8addb23582eda36a5b07798f
|
|
| MD5 |
349a693d9c90dc736f7faa05c6b1c073
|
|
| BLAKE2b-256 |
f6c5ef56bb316449d02c272e652f094626341d4f1f8d7522a128e3f6a5d144cd
|
File details
Details for the file c4dot5_decision_tree-1.2.1-py3-none-any.whl.
File metadata
- Download URL: c4dot5_decision_tree-1.2.1-py3-none-any.whl
- Upload date:
- Size: 50.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a5dbee8cc29c52abaa5217ed2bbce028275e527464e75fc24d6ee9d75b4dad1
|
|
| MD5 |
d32d4e5baac5a1962209bd0375719904
|
|
| BLAKE2b-256 |
cfabe4ce8d28a667346b65a52c427a3a6a21816fc6e357361ddafed0dcac2565
|