Beispiel #1
0
def cross(file='data/housingD.csv', rseed=1):
    def klass(test):
        return test.cells[train.klass[0].col]

    seed(rseed)
    tbl = discreteTable(file)
    n = 0
    abcd = Abcd()
    nLeaves = Num()
    nNodes = Num()
    for tests, train in xval(tbl):
        tree = tdiv(train)
        for node in dtnodes(tree):
            print node.branch
        nLeaves + len([n for n in dtleaves(tree)])
        nNodes + len([n for n in dtnodes(tree)])
        for test in tests:
            want = klass(test)
            got = classify(test, tree)
            abcd(want, got)
        exit()
    nl()
    abcd.header()
    abcd.report()
    print ":nodes", sorted(nNodes.some.all())
    print ":leaves", sorted(nLeaves.some.all())
Beispiel #2
0
def cross(file='data/housingD.csv',rseed=1):
  def klass(test):
    return test.cells[train.klass[0].col]
  seed(rseed)
  tbl = discreteTable(file)
  n=0
  abcd=Abcd()
  nLeaves=Num()
  nNodes=Num()
  for tests, train in xval(tbl):
     tree = tdiv(train)
     for node in dtnodes(tree):
       print node.branch
     nLeaves + len([n for n in dtleaves(tree)])
     nNodes +  len([n for n in dtnodes(tree)])
     for test in tests:
       want = klass(test)
       got  = classify(test,tree)
       abcd(want,got)
     exit()
  nl()
  abcd.header()
  abcd.report()
  print ":nodes",sorted(nNodes.some.all())
  print ":leaves",sorted(nLeaves.some.all())
Beispiel #3
0
def snl(file='data/poi-1.5D.csv', rseed=1, w=dict(_1=0, _0=1)):
    def klass(x):
        return x.cells[train.klass[0].col]

    def val((x, y)):
        return y if x == ninf else x

    seed(rseed)
    nl()
    print "#", file
    tbl = discreteTable(file)
    tree0 = tdiv(tbl)
    showTdiv(tree0)
    nl()
    old, better, worse = Sym(), Sym(), Sym()
    abcd1, abcd2 = Abcd(db=file, rx="where"), Abcd(db=file, rx="ranfor")
    abcd3 = Abcd(db=file, rx="logref")
    abcd4 = Abcd(db=file, rx="dt")
    abcd5 = Abcd(db=file, rx="nb")
    for tests, train in xval(tbl):
        learns(tests,
               train._rows,
               indep=lambda row: map(val, row.cells[:-2]),
               dep=lambda row: row.cells[-1],
               rf=abcd2,
               lg=abcd3,
               dt=abcd4,
               nb=abcd5),
        tree = tdiv(train)
        snakesAndLadders(tree, train, w)
        for test in tests:
            abcd1(actual=klass(test), predicted=classify(test, tree))
            a, b = improve(test, tree)
            old + a
            better + b
            _, c = degrade(test, tree)
            worse + c
    print "\n:asIs", old.counts
    print ":plan", better.counts
    print ":warn", worse.counts
    abcd1.header()
    abcd1.report()
    abcd2.report()
    abcd3.report()
    abcd4.report()
    abcd5.report()
Beispiel #4
0
def snl(file='data/poi-1.5D.csv',rseed=1,w=dict(_1=0,_0=1)):  
  def klass(x): return x.cells[train.klass[0].col]
  def val((x,y)):
    return y if x == ninf else x
  seed(rseed)
  nl(); print "#",file
  tbl = discreteTable(file)
  tree0 = tdiv(tbl)
  showTdiv(tree0); nl()
  old, better, worse = Sym(), Sym(), Sym()
  abcd1, abcd2  = Abcd(db=file,rx="where"), Abcd(db=file,rx="ranfor")
  abcd3 = Abcd(db=file, rx="logref")
  abcd4 = Abcd(db=file, rx="dt")
  abcd5 = Abcd(db=file, rx="nb")
  for tests, train in xval(tbl):
     learns(tests,train._rows,
            indep=lambda row: map(val,row.cells[:-2]),
            dep = lambda row: row.cells[-1],
            rf  = abcd2,
            lg  = abcd3,
            dt  = abcd4,
            nb  = abcd5),
     tree = tdiv(train)
     snakesAndLadders(tree,train,w)
     for test in tests:
       abcd1(actual    = klass(test),
            predicted = classify(test,tree))
       a,b  = improve(test,tree); old + a; better + b
       _,c  = degrade(test,tree);          worse  + c
  print "\n:asIs",old.counts
  print ":plan",better.counts
  print ":warn",worse.counts
  abcd1.header()
  abcd1.report()
  abcd2.report()
  abcd3.report()
  abcd4.report()
  abcd5.report()