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 -i https://test.pypi.org/simple/ 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
import sklearn as sk
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()
for rule in rules:
print(f"{rule}: {rules[rule]}")
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
Hashes for c4dot5-decision-tree-1.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d5e837e58921dd552a6bac463867a9129c508f79e93275784064d0965b81b39 |
|
MD5 | a703e0a7410e5970cf6fb55f9baf0577 |
|
BLAKE2b-256 | a0465713edc6e74aca324ed3df6ae80d06ad44dd957a101ffeaa3a9d7f2e8c34 |
Hashes for c4dot5_decision_tree-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57e1199d8a9c42f97b02d1b9a2245ff0a60e5ba0461e30079b046772cdcd834f |
|
MD5 | 16d3c190031cfc1f4df6454cd34d0366 |
|
BLAKE2b-256 | 4dc1090ade0e4c9cb14eae7c08933abfa8c53d082e218de320bbf8adb3ac8fe1 |