def testIrisNoisy(trainDataFile, testDataFile, attrDataFile):
    irisTree = DecisionTree(trainDataFile, testDataFile, attrDataFile)
    irisTree.loadData()
    irisTree.preprocessData()
    irisTree.splitDataSet(irisTree.getTrainData())
    trainData = irisTree.getTrainData()
    testData = irisTree.getTestData()
    attributes = irisTree.getAttributes()
    attrValues = irisTree.getAttrValues()
    validationData = irisTree.getValidationData()
    print(validationData)
    for rate in range(0, 21, 2):
        noisyData = addNoise(trainData, rate, irisTree.getClasses())
        irisTree.generateTree(noisyData)
        tree = irisTree.getTree()
        irisRulePrinter = RuleSetPrinter(tree, attrValues)
        print("\nNoise Rate (%): " + str(rate))
        print("--------Rule Set--------")
        irisRulePrinter.printRuleSet()
        rules = irisRulePrinter.getRules()
        testPred = Predictor(testData, validationData, attributes, attrValues,
                             tree, rules)
        #    testAcc = testPred.calculateRuleAccuracy(validationData, rules)
        testAcc = testPred.calculateRuleAccuracy(testData, rules)
        print("Test Accuracy (%): " + str(testAcc))
        print("----Post-pruning Rules----")
        pruneRules = testPred.postPruning()
        print(os.linesep.join(pruneRules))
        testPred = Predictor(testData, validationData, attributes, attrValues,
                             tree, pruneRules)
        testAcc = testPred.calculateRuleAccuracy(testData, pruneRules)
        print("Test Accuracy (%): " + str(testAcc))
def testIris(trainDataFile, testDataFile, attrDataFile):
    irisTree = DecisionTree(trainDataFile, testDataFile, attrDataFile)
    irisTree.loadData()
    irisTree.preprocessData()
    irisTree.splitDataSet(irisTree.getTrainData())
    trainData = irisTree.getTrainData()
    testData = irisTree.getTestData()
    validationData = irisTree.getValidationData()
    irisTree.generateTree(trainData)
    tree = irisTree.getTree()
    attributes = irisTree.getAttributes()
    attrValues = irisTree.getAttrValues()
    irisTreePrinter = TreePrinter(tree, attrValues)
    print("----------Tree----------")
    irisTreePrinter.printTree()

    irisRulePrinter = RuleSetPrinter(tree, attrValues)
    print("--------Rule Set--------")
    irisRulePrinter.printRuleSet()
    rules = irisRulePrinter.getRules()

    trainPred = Predictor(trainData, validationData, attributes, attrValues,
                          tree, rules)
    trainAcc = trainPred.calculateRuleAccuracy(trainData, rules)
    print("Training Accuracy (%): " + str(trainAcc))

    testPred = Predictor(testData, validationData, attributes, attrValues,
                         tree, rules)
    testAcc = testPred.calculateRuleAccuracy(testData, rules)
    print("Test Accuracy (%): " + str(testAcc))

    print("----Post-pruning Rules----")
    pruneRules = testPred.postPruning()
    print(os.linesep.join(pruneRules))
    trainPred = Predictor(trainData, validationData, attributes, attrValues,
                          tree, pruneRules)
    trainAcc = trainPred.calculateRuleAccuracy(trainData, pruneRules)
    print("Training Accuracy (%): " + str(trainAcc))

    testPred = Predictor(testData, validationData, attributes, attrValues,
                         tree, pruneRules)
    testAcc = testPred.calculateRuleAccuracy(testData, pruneRules)
    print("Test Accuracy (%): " + str(testAcc))