Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

c4dot5-decision-tree-1.2.1.tar.gz (42.5 kB view hashes)

Uploaded Source

Built Distribution

c4dot5_decision_tree-1.2.1-py3-none-any.whl (50.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page