示例#1
0
def DTfunc(arg1, arg2, arg3=None):
    #encode tree-depths
    if "balance.scale" in arg1:
        depth = 3
    if "nursery" in arg1:
        depth = 7
    if "led" in arg1:
        depth = 7
    if "synthetic.social" in arg1:
        depth = 8
    #Read training file
    Rf = ReadTrFile.ReadTrFile(arg1)
    #Read Testing file
    Tf = ReadTeFile.ReadTeFile(arg2)

    #Initializer the Trainer class
    Train = Training.Training(depth, Rf.D, Rf.dictfile, Rf.attributedict,
                              Rf.labeldict, Rf.avcdict)
    #Generate Decision Tree
    trlabeldict, dtroot = Train.GenDT()
    #Initialize Tester
    Test = Testing.Testing(dtroot, Tf.dictfile)
    #Perform Decision Tree based Testing
    prlabel = Test.parsetestfile()

    #Calculate and Print Confusion Matrix
    cm = utilities.CalcConMat(Tf.dictfile, prlabel, Rf.labeldict)

    #Calculate quality of classifer for report
    if arg3 == True:
        QualityCalc.QualityCalc(cm)
示例#2
0
def RTfunc(arg1, arg2, arg3=None):

    #encode num-trees
    if "balance.scale" in arg1:
        numtrees = 150
        numatt = 2
        depth = 2
        databag = 1
    if "nursery" in arg1:
        numtrees = 100
        numatt = 8
        depth = 7
        databag = 1
    if "led" in arg1:
        numtrees = 65
        numatt = 7
        depth = 7
        databag = 1
    if "synthetic.social" in arg1:
        numtrees = 135
        numatt = 12
        depth = 8
        databag = 1

    #Read Training file
    Rf = ReadTrFile.ReadTrFile(arg1)

    #Read Testing file
    Tf = ReadTeFile.ReadTeFile(arg2)

    #Build DT's and test them
    prlabel = {}
    for x in range(0, numtrees):
        Dr = []
        size = len(Rf.D)
        for y in range(0, size):
            #Sampling with replacement
            if databag == 1:
                index = random.randint(0, size - 1)
            else:
                index = y
            Dr.append(Rf.D[index])
        Train = Training.Training(depth, Dr, Rf.dictfile, Rf.attributedict)
        dtroot = Train.GenDTRF(numatt)
        Test = Testing.Testing(dtroot, Tf.dictfile, prlabel)
        prlabel = Test.parsetestfile()

    #Calculate Confusion Matrix for Random forest results
    cm = utilities.CalcConMat(Tf.dictfile, prlabel, Rf.labeldict)

    #Calculate quality
    if arg3 == True:
        QualityCalc.QualityCalc(cm)
示例#3
0
def main():
    arguments = parse_arguments()

    if arguments.test:
        Testing.Testing().run_tests()
    else:

        # process input file and store the events read
        events = utility.process_input_data(arguments.input_file)

        # create moving average class with event and window size
        moving_average = MovingAverage.MovingAverage(events, arguments.window)

        # perform moving average time calculation
        average_times = moving_average.moving_average()

        # for output in average_times:
        utility.log_average_time(arguments.input_file, arguments.print,
                                 average_times, arguments.output_file)
import Testing
import Training
# /////////////////////////////////////////////////////////////////
x = float(input("Enter 1 To train Or 2 To Test : "))
if x == 1:
    train = Training.Training()
    train.training()
else:
    c = Testing.Testing()
    c.testing()

示例#5
0
    plt.title("Report")
    iteration = []
    dt, dl, td = Utils.Utils(dt, dl, td).orderData(3)
    seper = 5
    testArgs = range(seper)
    w_per = [[], [], [], [], []]
    w_pa = [[], [], [], [], []]
    w_svm = [[], [], [], [], []]
    tester = [Training, Training, Training, Training, Training]
    for tr in [0]:
        for i in testArgs:
            i = int(i)
            iteration.append(i)
            w_per[i], w_pa[i], w_svm[i] = Training.Training(dt, dl,
                                                            params).train(i)
            tester[i] = Testing.Testing(dt, dl, w_per[i], w_pa[i], w_svm[i])
            if len(sys.argv) == 3:  # debug mode
                t1, t2, t3 = tester[i].testStatistic(i)
                succRateinPER.append(t1)
                succRateinPA.append(t2)
                succRateinSVM.append(t3)
                print("succeeds rate: per:", t1, " pa:", t2, " svm:", t3)

    if len(sys.argv) > 3:  # submit mode
        Testing.Testing.testerSubmit(tester, td)
        # tester.test(td)
    else:
        plt.plot(testArgs, succRateinSVM, label="SVM {}".format(tr))
        succRateinSVM = []
        plt.plot(testArgs, succRateinPA, label="PA {} ".format(tr))
        succRateinPA = []
          "\n")

    # @Kmeans
    centroids = Kmeans(x_train, 11)
    #print("\nCluster Centroids after Kmeans: \n", centroids)

    # PCA
    pcaValues = PCA(x_train, 5)
    print("\nPCA with 5 features: \n")

    random_forest_predictions = RandomForest(x_train, y_train, x_test)
    print("Accuracy of Random Forest: ",
          Accuracy(y_test, random_forest_predictions))

    predicitons = SklearnSupervisedLearning(x_train, y_train, x_test)
    test = Testing(predicitons, x_test, y_test, True)
    test.run()

    SklearnVotingClassifier(x_train, y_train, x_test)
    testVoting = Testing([SklearnVotingClassifier(x_train, y_train, x_test)],
                         x_test, y_test, True)
    testVoting.run()
    endTime = timeit.default_timer()
    print("Total Project time ", endTime - startTime)

    tuned_parameters = [{
        'kernel': ['rbf'],
        'gamma': [1e-3],
        'C': [1, 10, 100, 500, 1000]
    }, {
        'kernel': ['linear'],
示例#7
0
# -*- coding: utf-8 -*-

from Testing import *
t = Testing()
t.init()
t.setTime("22h02m0s")
t.setRef(1, "2h31m49s", "89º15'51''", "22h04m20s", "0º27'09''", "36º49'17''")
t.setRef(2, "18h36m56s", "38º47'03''", "22h05m07s", "78º10'04''", "70º05'19''")
#t.goto1("100","160")
t.goto("18h03m48s", "24º23'00''", "22h06m52s")
#t.goto("13h17m55s", "8º29'04''", "22h07m51s")