Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Chih-Ling-Hsu/DecisionTree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Classification: Decision Tree

Python implementation of Decision Tree. (a practice)

Usage

1. Import the class

from DecisionTree import *

2. Create an object

dt = DecisionTree(method="C4.5", max_depth=3)

Parameters -

  • method (string) “ID3”,or “C4.5”
  • max_depth (int) the maximum depth of the tree

3. Train a model

dt.fit(X, y)

Parameters -

  • X (pandas.DataFrame) attributes of samples
  • y (pandas.DataFrame) labels of samples, must have the same number of rows as X

4. Show the trained model

dt.exportTree()

Example output -

--- [Outlook]
    --- overcast
        ===> yes
    --- rain
        --- [Wind]
            --- high
                ===> no
            --- low
                ===> yes
    --- sun
        --- [Humidity]
            --- <77.5
                ===> yes
            --- >=77.5
                ===> no

5. Predict with the model

y_pred = dt.predict(X)

Parameters -

  • X (pandas.DataFrame) attributes of samples

Return -

  • y_pred (list) prediction of labels for each sample

About

Python implementation of decision tree (a practice)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages