Python implementation of Decision Tree. (a practice)
from DecisionTree import *dt = DecisionTree(method="C4.5", max_depth=3)Parameters -
- method (string) “ID3”,or “C4.5”
- max_depth (int) the maximum depth of the tree
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
dt.exportTree()Example output -
--- [Outlook]
--- overcast
===> yes
--- rain
--- [Wind]
--- high
===> no
--- low
===> yes
--- sun
--- [Humidity]
--- <77.5
===> yes
--- >=77.5
===> no
y_pred = dt.predict(X)Parameters -
- X (pandas.DataFrame) attributes of samples
Return -
- y_pred (list) prediction of labels for each sample