def run_AVG_DT_paper(_xTr, yTr, _xTe, yTe): xTr = change_to_avg(_xTr) xTe = change_to_avg(_xTe) clf = DT_AVG() clf.fit(xTr, yTr) print( 'JapaneseVowels AVG acc is {0}'.format( clf.score(xTe, yTe) ) )
from myDT_AVG import DT_AVG def change_to_pdf_single(data): (N, M) = data.shape return [[{data[i][j]: 1.0} for j in xrange(M)] for i in xrange(N)] if __name__ == '__main__': iris = load_iris() xTr, xTe, yTr, yTe = cross_validation.train_test_split(iris.data, iris.target, test_size=0.1, random_state=692) #clf = DecisionTreeClassifier() clf = DT_AVG(debug=True) clf.fit(xTr, yTr) acc = clf.score(xTe, yTe) print("iris DT acc is {0}".format(acc)) pdfTr = change_to_pdf_single(xTr) pdfTe = change_to_pdf_single(xTe) clf = UDT(debug=True) clf.fit(pdfTr, yTr) acc = clf.score(pdfTe, yTe) print("iris UDT acc is {0}".format(acc)) #xTr,xTe = cross_validation.train_test_split(iris.data, test_size = 0.2, random_state=100) #yTr,yTe = cross_validation.train_test_split(iris.target, test_size = 0.2, random_state=100) clf = DT_AVG() print("iris DT 10-forld acc is {0}".format(
from sklearn import cross_validation from sklearn.datasets import load_iris #from sklearn.tree import DecisionTreeClassifier from myUDT import UDT from myDT_AVG import DT_AVG def change_to_pdf_single(data): (N,M) = data.shape return [ [{data[i][j]:1.0} for j in xrange(M)] for i in xrange(N) ] if __name__ == '__main__': iris = load_iris() xTr, xTe, yTr, yTe = cross_validation.train_test_split( iris.data, iris.target, test_size=0.1, random_state=692) #clf = DecisionTreeClassifier() clf = DT_AVG(debug=True) clf.fit(xTr, yTr) acc = clf.score(xTe, yTe) print( "iris DT acc is {0}".format(acc) ) pdfTr = change_to_pdf_single(xTr) pdfTe = change_to_pdf_single(xTe) clf = UDT(debug=True) clf.fit(pdfTr, yTr) acc = clf.score(pdfTe, yTe) print( "iris UDT acc is {0}".format(acc) ) #xTr,xTe = cross_validation.train_test_split(iris.data, test_size = 0.2, random_state=100) #yTr,yTe = cross_validation.train_test_split(iris.target, test_size = 0.2, random_state=100) clf = DT_AVG() print( "iris DT 10-forld acc is {0}".format(