Exemple #1
0
def main(c = "decision_tree", option = "IG", dataset = "iris", ratio = 0.8):

	classifier_types = {0: "decision_tree", 1: "naive_bayes", 2: "neural_net"}
	options = {0:["IG", "IGR"], 1:["normal"], 2:["shallow", "medium"]}

	ratio = float(ratio)

	if dataset == "monks":
		(training, test) = load_data.load_monks(ratio)
	elif dataset == "congress":
		(training, test) = load_data.load_congress_data(ratio)
	elif dataset == "iris":
		(training, test) = load_data.load_iris(ratio)
	else:
		print "Error: Cannot find dataset name."
		return

	print "Training... Please hold."
	# classifier_types = {0: "decision_tree", 2: "neural_net"}
	# options = {0:["IG", "IGR"], 2:["shallow", "medium"]}
	# (training, test) = load_data.load_iris(0.8)
	# nn_classifier = Classifier(classifier_type="neural_net", option = "medium")
	# nn_classifier.train(training)
	# nn_classifier.test(test)

	# print test
	# (training, test) = load_data.load_congress_data(0.8)
	# print test
	# (training, test) = load_data.load_monks(1)
	# print test	

	# (training, test) = load_data.load_iris(0.8)
	# print training
	# "option = IG/IGR"
	# dt_classifier = Classifier(classifier_type="decision_tree", weights=[], option="IG")
	# dt_classifier.train(training)
	# dt_classifier.test(test)
	# for i, c in classifier_types.iteritems():
	# 	for option in options[i]:
	print "                                                                 "
	print "================================================================="
	print "Dataset    = ", dataset
	print "Classifier = ", c
	print "Option     = ", option
	classifier = Classifier(classifier_type=c, weights = [], option = option)
	classifier.train(training)
	classifier.test(test)
	print "================================================================="
	print "                                                                 "
	# option value could be either shallow(3 layers) or medium(5)
	# nn_classifier = Classifier(classifier_type="neural_net", option = "medium")
	# nn_classifier.train(training)
	# nn_classifier.test(test)
	return 
def trainNtest(args):
    classifierType = ["decision_tree", "naive_bayes", "neural_network"]
    data_set = ["congress", "monk", "iris"]

    
    data = ""
    if len(args) == 4:
        if args[0][3:] == "congress":
            data = ld.load_congress_data(int(args[1][3:]) / 100.0)
            num_input = 16
            num_output = 2 
        elif args[0][3:] == "monk":
            data = ld.load_monks(int(args[1]))
            num_input = 6
            num_output = 2 
        elif args[0][3:] == "iris":
            data = ld.load_iris(int(args[1][3:]) / 100.0)
            num_input = 4
            num_output = 3
        else:
            print "INVALID DATA NAME"
            return
        method_num = int(args[2][3])
        kwargs = {}
        if method_num == 0 or method_num == 2:
            kwargs[1] = args[2][5]
            kwargs[2] = args[2][7]
            classifier = Classifier(classifierType[int(args[2][3])], one=args[2][5], two=args[2][7], num_input=num_input, num_output=num_output)
        else:
            classifier = Classifier(classifierType[int(args[2][3])])
    else:
        print "ERROR: NEED 4 PARAMETERS"
        return 


    #pdb.set_trace()
    #nb = Naive_Bayes("naive_bayes")

    #classifier = Classifier(classifierType[1])
    #data = ld.load_congress_data(.85)

    #data = ld.load_iris(.70)

    #pdb.set_trace()

    classifier.train(data[0])


    if args[3] == "-test":
        classifier.test(data[1])
    else:
        classifier.test(data[0])
Exemple #3
0
from nb import GNB
from tree import DT
import random
import math
import numpy.matlib

# number of class of each data set
ncIris = 3
ncCongress = 2
ncMonks = 2
# Dataset reading
trainSetIris = np.matrix(load_iris(0.7)[0])
testSetIris = np.matrix(load_iris(0.7)[1])
trainSetCongress = np.matrix(load_congress_data(0.7)[0])
testSetCongress = np.matrix(load_congress_data(0.7)[1])
trainM1 = np.matrix(load_monks(1)[0])
testM1 = np.matrix(load_monks(1)[1])
trainM2 = np.matrix(load_monks(2)[0])
testM2 = np.matrix(load_monks(2)[1])
trainM3 = np.matrix(load_monks(3)[0])
testM3 = np.matrix(load_monks(3)[1])

# Decision Tree on Congress using IG
print "1. DT, Congress, IG--------------------------------"
model0 = DT()
model0.train(trainSetCongress, ncCongress, 1)
model0.test(testSetCongress, ncCongress, 1)
# Prune
model0.prune(trainSetCongress, ncCongress)
print "2. -----------prune----------"
model0.test(testSetCongress, ncCongress, 1)
    data = sys.argv[2]

params = dict()

(train_data, test_data) = (None, None)

if data=="congress":
    (train_data, test_data) = load_data.load_congress_data(0.7)
elif data=="iris":
    (train_data, test_data) = load_data.load_iris(0.7)
elif data=="monk":
    i = 3
    if classifier_type == "decision_tree":
        i = 4
    numb = sys.argv[i]
    (train_data, test_data) = load_data.load_monks(int(numb))

params = dict()

if classifier_type == "neural_network":
    i=3
    if data=="monk":
        i=4
    if len(sys.argv) >= (i+1):
        params["activation"] = sys.argv[i]
    if len(sys.argv) >= (i+2):
        params["learning_rate"] = float(sys.argv[i+1])
    if len(sys.argv) >= (i+3):
        params["epochs"] = int(sys.argv[i+2])