from ca.pfv.spmf.algorithms.classifiers.decisiontree.id3 import AlgoID3
from ca.pfv.spmf.algorithms.classifiers.decisiontree.id3 import DecisionTree
# create input decision tree
data="""play outlook temp humid wind
no sunny hot high weak
no sunny hot high strong
yes overcast hot high weak
yes rain mild high weak
yes rain cool normal weak
no rain cool normal strong
yes overcast mild high strong
no sunny mild high weak
yes sunny cool normal weak
yes rain mild normal weak
yes sunny mild normal strong
yes overcast hot normal weak
yes overcast cool normal strong
no rain mild high strong
"""
file = open("data.txt", "w")
file.write(data)
file.close()
# use 0.4: means a minsup of 2 transaction (we used a relative support)
out="output.txt"
alg=AlgoID3();
# the separator used in the file to separate values (by default it is a space)
tree = alg.runAlgorithm("data.txt", "play", " ");
tree.print()
# Use the decision tree to make predictions
# For example, we want to predict the class of an instance:
instance = [None, "sunny", "hot", "normal", "weak"]
prediction = tree.predictTargetAttributeValue(instance);
print "The class that is predicted is: ",prediction
Ads help maintain this website.