Ejemplo n.º 1
0
def main():
    #import the data from a csv
    car_data = np.genfromtxt('car_data.csv', delimiter=',')

    #call the tree creator module and pass the name of the json file to it
    dTree = DecisionTree('jsonTrees/' + testName + '.json')

    scores = []
    #track the best score and data
    best = [0, 0]
    test = []

    for data in car_data:

        #change the inputs for each of the cars in the tree
        dTree.changeInputs(convertCarData(data))
        #get the score for that car
        score = dTree.run()

        #check if its the highest
        if (score > best[0]):
            best[0] = score
            best[1] = data
        #add it to the list of scores
        scores.append(score)
        test.append([score, data.tolist()])

    #print("best",best[0],best[1])

    test = sorted(test, key=lambda x: x[0], reverse=True)

    pprint(test[0:3])

    #create a normilized histagram of the scores
    n, bins, patches = plt.hist(scores,
                                normed=1,
                                facecolor='green',
                                alpha=0.75)
    plt.title(testName + wValue)
    #save the image to a file
    plt.savefig("graphs/" + testName + wValue + ".png", bbox_inches='tight')
    #show the image
    plt.show()
Ejemplo n.º 2
0
def main():

    fmemFile = File("fmemFile.csv")

    #import the data from a csv
    car_data = np.genfromtxt('car_data.csv', delimiter=',')

    #call the tree creator module and pass the name of the json file to it
    aTree = DecisionTree('jsonTrees/' + testA + '.json')
    nTree = DecisionTree('jsonTrees/' + testN + '.json')
    eTree = DecisionTree('jsonTrees/' + testE + '.json')

    #iterator = car_data[np.random.randint(car_data.shape[0], size=100), :]
    #iterator = car_data
    iterator = inputs2

    for inputs in iterator:

        #change the inputs for each of the cars in the tree

        #inputs = convertCarData(inputs)
        aTree.changeInputs(inputs)
        nTree.changeInputs(inputs)
        eTree.changeInputs(inputs)

        #get the score for that car

        aScore = aTree.run()
        nScore = nTree.run()
        eScore = eTree.run()

        print("Inputs:", inputs)
        print("ASCORE #######:", aScore)
        print("NSCORE #######:", nScore)
        print("ESCORE #######:", eScore)

        eScore = np.array(eScore)

        f1 = MemFunc('trap', aScore)
        X = np.arange(0, 1, .05)

        l1, = plt.plot(X, [f1.memFunc(i) for i in X],
                       c='r',
                       linewidth=2.0,
                       label="AlphaCuts")
        l2, = plt.plot(eScore[:, 0],
                       eScore[:, 1],
                       c='b',
                       linewidth=2.0,
                       label="Extention Principle")
        l3 = plt.axvline(nScore, c='g', linewidth=2.0, label="Crisp")

        plt.legend(handles=[l1, l2, l3])
        plt.title("Regular Title")
        plt.xlabel("Output Score")
        plt.ylabel("Membership Value")

        #Batch Save Rember to remove input
        #plt.savefig("test.png")

        plt.show()
        break