Beispiel #1
0
def testing_gain_increments(increments=[]):
    classresults = {}

    for increment in increments:
        tree = treepredict.buildtree(train_data,
                                     gain_increment=increment,
                                     gain_threshold=0,
                                     instance_minimum=1)

        trainConfMat, crTrain = treepredict.testTree(train_data, tree)
        print 'Training set confusion matrix (Classification rate:', crTrain, '):'
        for row in trainConfMat:
            print '\t'.join(map(lambda x: str(x), row))

        print ''

        testConfMat, crTest = treepredict.testTree(test_data, tree)
        print 'Test set confusion matrix (Classification rate:', crTest, '):'
        for row in testConfMat:
            print '\t'.join(map(lambda x: str(x), row))

        print ''

        classresults[increment] = [crTest]

    return classresults
def testing_gain_increments(increments=[]):
  classresults={}
  
  for increment in increments:
    tree=treepredict.buildtree(train_data,gain_increment=increment,gain_threshold=0,instance_minimum=1)

    trainConfMat, crTrain = treepredict.testTree(train_data, tree)
    print 'Training set confusion matrix (Classification rate:', crTrain,'):'
    for row in trainConfMat:
      print '\t'.join(map(lambda x:str(x), row))

    print ''
  
    testConfMat, crTest  = treepredict.testTree(test_data,  tree) 
    print 'Test set confusion matrix (Classification rate:', crTest,'):'
    for row in testConfMat:
      print '\t'.join(map(lambda x:str(x), row))

    print ''

    
    classresults[increment]=[crTest]

  return classresults
import fileinput
import Image
import ImageDraw


# If the last parameter is set to 0, then all attributes other than 'age' and 'war' would be used.

train_data, test_data = fileinput.loadDataset(5, ['age','gender','occupation','fantasy','film-noir', 'drama', 'western'], 1)

tree=treepredict.buildtree(train_data,gain_increment=0,gain_threshold=0,instance_minimum=100)

# Let's see what it looks like...
print "\nFinal tree...\n"
treepredict.printtree(tree)

trainConfMat, crTrain = treepredict.testTree(train_data, tree)
print 'Training set confusion matrix (Classification rate:', crTrain,'):'
for row in trainConfMat:
    print '\t'.join(map(lambda x:str(x), row))

print ''
  

testConfMat, crTest  = treepredict.testTree(test_data,  tree) 
print 'Test set confusion matrix (Classification rate:', crTest,'):'
for row in testConfMat:
    print '\t'.join(map(lambda x:str(x), row))

print ''
    
    
Beispiel #4
0
import fileinput
import Image
import ImageDraw


# If the last parameter is set to 0, then all attributes other than 'age' and 'war' would be used.

train_data, test_data = fileinput.loadDataset(2, ['age', 'gender','occupation','unknown genre','film-noir', 'horror', 'western'], 1)

tree=treepredict.buildtree(train_data,gain_increment=0,gain_threshold=0,instance_minimum=0)

# Let's see what it looks like...
print "\nFinal tree...\n"
treepredict.printtree(tree)

trainConfMat, crTrain = treepredict.testTree(train_data, tree)
print 'Training set confusion matrix (Classification rate:', crTrain,'):'
for row in trainConfMat:
    print '\t'.join(map(lambda x:str(x), row))

print ''
  

testConfMat, crTest  = treepredict.testTree(test_data,  tree) 
print 'Test set confusion matrix (Classification rate:', crTest,'):'
for row in testConfMat:
    print '\t'.join(map(lambda x:str(x), row))

print ''