Ejemplo n.º 1
0
from data import Data
from naivebayes import NaiveBayes

filename = "datasets/weatherNominal.td"
## filename = "datasets/titanic.td"
## filename = "datasets/cmc.td"

d = Data(filename)
d.report()

pr = NaiveBayes(d)
pr.train()
pr.show()

for (v, c_true) in d.test_set:
    c_pred = pr.predict(v)[0]
    print(v, ":")
    print("   ", c_pred, "( true class:", c_true, ")")

##    print(pr.predict(("Class:1st","Sex:Female","Age:Child")))

##    print(pr.predict(("Class:Crew","Sex:Female","Age:Child")))
Ejemplo n.º 2
0
    #pos_class = "Survived:No"

    # datafile = "cmcTr.txt"
    # pos_class = "contraceptive-method:none"

    d = Data(datafile)

    prnb = NaiveBayes(d)
    prnb.train()

    r = Roc(prnb, pos_class)

    r.do_curve()

    print "Predicting", pos_class, "for data file", datafile,
    print "with", int(r.curve[2]), "positive instances and", int(
        r.curve[3]), "negative instances"

    if print_numbers:
        prnb.show()

        print "Scores for predicting", pos_class, ":"
        for e in sorted(r.preds):
            print e
        print "==="
        print "Curve coordinates:"
        for e in zip(r.curve[0], r.curve[1]):
            print e

    r.draw_curve()