def test_Compare(self): mxKFoldRun = MxKFoldRun(5, 2) combined5x2t = Combined5x2t() experimentPerformance1 = mxKFoldRun.execute( Experiment(C45(), C45Parameter(1, True, 0.2), self.iris)) experimentPerformance2 = mxKFoldRun.execute( Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.iris)) self.assertAlmostEqual( 0.186, combined5x2t.compare(experimentPerformance1, experimentPerformance2).getPValue(), 3) experimentPerformance1 = mxKFoldRun.execute( Experiment(C45(), C45Parameter(1, True, 0.2), self.tictactoe)) experimentPerformance2 = mxKFoldRun.execute( Experiment(Bagging(), BaggingParameter(1, 50), self.tictactoe)) self.assertAlmostEqual( 0.0000059, combined5x2t.compare(experimentPerformance1, experimentPerformance2).getPValue(), 7) experimentPerformance1 = mxKFoldRun.execute( Experiment(Lda(), Parameter(1), self.dermatology)) experimentPerformance2 = mxKFoldRun.execute( Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.dermatology)) self.assertAlmostEqual( 0.9819, combined5x2t.compare(experimentPerformance1, experimentPerformance2).getPValue(), 4) experimentPerformance1 = mxKFoldRun.execute( Experiment(Dummy(), Parameter(1), self.nursery)) experimentPerformance2 = mxKFoldRun.execute( Experiment(NaiveBayes(), Parameter(1), self.nursery)) self.assertAlmostEqual( 0.0, combined5x2t.compare(experimentPerformance1, experimentPerformance2).getPValue(), 4) experimentPerformance1 = mxKFoldRun.execute( Experiment(NaiveBayes(), Parameter(1), self.car)) experimentPerformance2 = mxKFoldRun.execute( Experiment(Bagging(), BaggingParameter(1, 50), self.car)) self.assertAlmostEqual( 0.00043, combined5x2t.compare(experimentPerformance1, experimentPerformance2).getPValue(), 5) experimentPerformance1 = mxKFoldRun.execute( Experiment(Knn(), KnnParameter(1, 3, EuclidianDistance()), self.bupa)) experimentPerformance2 = mxKFoldRun.execute( Experiment(Lda(), Parameter(1), self.bupa)) self.assertAlmostEqual( 0.0663, combined5x2t.compare(experimentPerformance1, experimentPerformance2).getPValue(), 4)
def test_SubSetSelectionC45(self): kFoldRun = KFoldRun(10) forwardSelection = ForwardSelection() experiment = Experiment(C45(), C45Parameter(1, True, 0.2), self.iris) self.assertAlmostEqual(1, forwardSelection.execute(kFoldRun, experiment).size()) backwardSelection = BackwardSelection(self.iris.attributeCount()) self.assertAlmostEqual(3, backwardSelection.execute(kFoldRun, experiment).size()) floatingSelection = FloatingSelection() self.assertAlmostEqual(1, floatingSelection.execute(kFoldRun, experiment).size())
def test_Compare(self): kFoldRun = KFoldRun(10) pairedt = Pairedt() experimentPerformance1 = kFoldRun.execute(Experiment(C45(), C45Parameter(1, True, 0.2), self.iris)) experimentPerformance2 = kFoldRun.execute(Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.iris)) self.assertAlmostEqual(0.379, pairedt.compare(experimentPerformance1, experimentPerformance2).getPValue(), 3) experimentPerformance1 = kFoldRun.execute(Experiment(C45(), C45Parameter(1, True, 0.2), self.tictactoe)) experimentPerformance2 = kFoldRun.execute(Experiment(Bagging(), BaggingParameter(1, 50), self.tictactoe)) self.assertAlmostEqual(0.00000692, pairedt.compare(experimentPerformance1, experimentPerformance2).getPValue(), 7) experimentPerformance1 = kFoldRun.execute(Experiment(Lda(), Parameter(1), self.dermatology)) experimentPerformance2 = kFoldRun.execute(Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.dermatology)) self.assertAlmostEqual(0.7842, pairedt.compare(experimentPerformance1, experimentPerformance2).getPValue(), 4) experimentPerformance1 = kFoldRun.execute(Experiment(Dummy(), Parameter(1), self.nursery)) experimentPerformance2 = kFoldRun.execute(Experiment(NaiveBayes(), Parameter(1), self.nursery)) self.assertAlmostEqual(0.0, pairedt.compare(experimentPerformance1, experimentPerformance2).getPValue(), 4) experimentPerformance1 = kFoldRun.execute(Experiment(NaiveBayes(), Parameter(1), self.car)) experimentPerformance2 = kFoldRun.execute(Experiment(Bagging(), BaggingParameter(1, 50), self.car)) self.assertAlmostEqual(0.00000336, pairedt.compare(experimentPerformance1, experimentPerformance2).getPValue(), 7) experimentPerformance1 = kFoldRun.execute(Experiment(Knn(), KnnParameter(1, 3, EuclidianDistance()), self.bupa)) experimentPerformance2 = kFoldRun.execute(Experiment(Lda(), Parameter(1), self.bupa)) self.assertAlmostEqual(0.1640, pairedt.compare(experimentPerformance1, experimentPerformance2).getPValue(), 4)
def test_C45(self): c45 = C45() c45Parameter = C45Parameter(1, True, 0.2) discreteToIndexed = LaryToBinary(self.car) discreteToIndexed.convert() c45.train(self.car.getInstanceList(), c45Parameter) self.assertAlmostEqual(3.99, 100 * c45.test(self.car.getInstanceList()).getErrorRate(), 2) discreteToIndexed = LaryToBinary(self.tictactoe) discreteToIndexed.convert() c45.train(self.tictactoe.getInstanceList(), c45Parameter) self.assertAlmostEqual(3.34, 100 * c45.test(self.tictactoe.getInstanceList()).getErrorRate(), 2) discreteToIndexed = LaryToBinary(self.nursery) discreteToIndexed.convert() c45.train(self.nursery.getInstanceList(), c45Parameter) self.assertAlmostEqual(0.84, 100 * c45.test(self.nursery.getInstanceList()).getErrorRate(), 2)
def test_C45(self): c45 = C45() c45Parameter = C45Parameter(1, True, 0.2) discreteToContinuous = DiscreteToContinuous(self.car) discreteToContinuous.convert() c45.train(self.car.getInstanceList(), c45Parameter) self.assertAlmostEqual( 29.98, 100 * c45.test(self.car.getInstanceList()).getErrorRate(), 2) discreteToContinuous = DiscreteToContinuous(self.tictactoe) discreteToContinuous.convert() c45.train(self.tictactoe.getInstanceList(), c45Parameter) self.assertAlmostEqual( 34.66, 100 * c45.test(self.tictactoe.getInstanceList()).getErrorRate(), 2)
def test_Train(self): c45 = C45() c45Parameter = C45Parameter(1, True, 0.2) c45.train(self.iris.getInstanceList(), c45Parameter) self.assertAlmostEqual(4.00, 100 * c45.test(self.iris.getInstanceList()).getErrorRate(), 2) c45.train(self.bupa.getInstanceList(), c45Parameter) self.assertAlmostEqual(42.03, 100 * c45.test(self.bupa.getInstanceList()).getErrorRate(), 2) c45.train(self.dermatology.getInstanceList(), c45Parameter) self.assertAlmostEqual(4.64, 100 * c45.test(self.dermatology.getInstanceList()).getErrorRate(), 2) c45.train(self.car.getInstanceList(), c45Parameter) self.assertAlmostEqual(6.48, 100 * c45.test(self.car.getInstanceList()).getErrorRate(), 2) c45.train(self.tictactoe.getInstanceList(), c45Parameter) self.assertAlmostEqual(8.77, 100 * c45.test(self.tictactoe.getInstanceList()).getErrorRate(), 2) c45.train(self.nursery.getInstanceList(), c45Parameter) self.assertAlmostEqual(2.31, 100 * c45.test(self.nursery.getInstanceList()).getErrorRate(), 2) c45.train(self.chess.getInstanceList(), c45Parameter) self.assertAlmostEqual(52.57, 100 * c45.test(self.chess.getInstanceList()).getErrorRate(), 2)
def test_Execute(self): mxKFoldRun = MxKFoldRun(5, 2) experimentPerformance = mxKFoldRun.execute( Experiment(C45(), C45Parameter(1, True, 0.2), self.iris)) self.assertAlmostEqual( 6.13, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(C45(), C45Parameter(1, True, 0.2), self.tictactoe)) self.assertAlmostEqual( 23.51, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(Knn(), KnnParameter(1, 3, EuclidianDistance()), self.bupa)) self.assertAlmostEqual( 37.05, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(Knn(), KnnParameter(1, 3, EuclidianDistance()), self.dermatology)) self.assertAlmostEqual( 15.41, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(Lda(), Parameter(1), self.bupa)) self.assertAlmostEqual( 34.72, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(Lda(), Parameter(1), self.dermatology)) self.assertAlmostEqual( 4.04, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.iris)) self.assertAlmostEqual( 5.2, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.dermatology)) self.assertAlmostEqual( 5.46, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(NaiveBayes(), Parameter(1), self.car)) self.assertAlmostEqual( 16.52, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(NaiveBayes(), Parameter(1), self.nursery)) self.assertAlmostEqual( 9.80, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(Bagging(), BaggingParameter(1, 50), self.tictactoe)) self.assertAlmostEqual( 8.77, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(Bagging(), BaggingParameter(1, 50), self.car)) self.assertAlmostEqual( 9.77, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(Dummy(), Parameter(1), self.nursery)) self.assertAlmostEqual( 67.09, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = mxKFoldRun.execute( Experiment(Dummy(), Parameter(1), self.iris)) self.assertAlmostEqual( 70.53, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2)
def test_Execute(self): kFoldRun = KFoldRun(10) experimentPerformance = kFoldRun.execute( Experiment(C45(), C45Parameter(1, True, 0.2), self.iris)) self.assertAlmostEqual( 6.00, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(C45(), C45Parameter(1, True, 0.2), self.tictactoe)) self.assertAlmostEqual( 18.78, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(Knn(), KnnParameter(1, 3, EuclidianDistance()), self.bupa)) self.assertAlmostEqual( 36.85, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(Knn(), KnnParameter(1, 3, EuclidianDistance()), self.dermatology)) self.assertAlmostEqual( 10.92, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(Lda(), Parameter(1), self.bupa)) self.assertAlmostEqual( 31.61, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(Lda(), Parameter(1), self.dermatology)) self.assertAlmostEqual( 3.30, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.iris)) self.assertAlmostEqual( 5.33, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.dermatology)) self.assertAlmostEqual( 3.81, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(NaiveBayes(), Parameter(1), self.car)) self.assertAlmostEqual( 14.88, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(NaiveBayes(), Parameter(1), self.nursery)) self.assertAlmostEqual( 9.71, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(Bagging(), BaggingParameter(1, 50), self.tictactoe)) self.assertAlmostEqual( 3.55, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(Bagging(), BaggingParameter(1, 50), self.car)) self.assertAlmostEqual( 6.77, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(Dummy(), Parameter(1), self.nursery)) self.assertAlmostEqual( 67.12, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = kFoldRun.execute( Experiment(Dummy(), Parameter(1), self.iris)) self.assertAlmostEqual( 79.33, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2)
def test_Execute(self): stratifiedMxKRun = StratifiedMxKFoldRun(5, 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(C45(), C45Parameter(1, True, 0.2), self.iris)) self.assertAlmostEqual( 8.00, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(C45(), C45Parameter(1, True, 0.2), self.tictactoe)) self.assertAlmostEqual( 22.03, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(Knn(), KnnParameter(1, 3, EuclidianDistance()), self.bupa)) self.assertAlmostEqual( 33.33, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(Knn(), KnnParameter(1, 3, EuclidianDistance()), self.dermatology)) self.assertAlmostEqual( 13.66, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(Lda(), Parameter(1), self.bupa)) self.assertAlmostEqual( 33.05, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(Lda(), Parameter(1), self.dermatology)) self.assertAlmostEqual( 3.55, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.iris)) self.assertAlmostEqual( 6.00, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.dermatology)) self.assertAlmostEqual( 4.66, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(NaiveBayes(), Parameter(1), self.car)) self.assertAlmostEqual( 15.11, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(NaiveBayes(), Parameter(1), self.nursery)) self.assertAlmostEqual( 9.68, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(Bagging(), BaggingParameter(1, 50), self.tictactoe)) self.assertAlmostEqual( 9.29, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(Bagging(), BaggingParameter(1, 50), self.car)) self.assertAlmostEqual( 9.20, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(Dummy(), Parameter(1), self.nursery)) self.assertAlmostEqual( 66.67, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = stratifiedMxKRun.execute( Experiment(Dummy(), Parameter(1), self.iris)) self.assertAlmostEqual( 66.67, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2)
def test_Execute(self): bootstrapRun = BootstrapRun(10) experimentPerformance = bootstrapRun.execute( Experiment(C45(), C45Parameter(1, True, 0.2), self.iris)) self.assertAlmostEqual( 4.33, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(C45(), C45Parameter(1, True, 0.2), self.tictactoe)) self.assertAlmostEqual( 13.16, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(Knn(), KnnParameter(1, 3, EuclidianDistance()), self.bupa)) self.assertAlmostEqual( 24.84, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(Knn(), KnnParameter(1, 3, EuclidianDistance()), self.dermatology)) self.assertAlmostEqual( 8.01, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(Lda(), Parameter(1), self.bupa)) self.assertAlmostEqual( 32.03, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(Lda(), Parameter(1), self.dermatology)) self.assertAlmostEqual( 2.95, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.iris)) self.assertAlmostEqual( 3.27, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(LinearPerceptron(), LinearPerceptronParameter(1, 0.1, 0.99, 0.2, 100), self.dermatology)) self.assertAlmostEqual( 2.65, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(NaiveBayes(), Parameter(1), self.car)) self.assertAlmostEqual( 14.75, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(NaiveBayes(), Parameter(1), self.nursery)) self.assertAlmostEqual( 9.71, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(Bagging(), BaggingParameter(1, 50), self.tictactoe)) self.assertAlmostEqual( 3.00, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(Bagging(), BaggingParameter(1, 50), self.car)) self.assertAlmostEqual( 3.44, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(Dummy(), Parameter(1), self.nursery)) self.assertAlmostEqual( 66.79, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2) experimentPerformance = bootstrapRun.execute( Experiment(Dummy(), Parameter(1), self.iris)) self.assertAlmostEqual( 66.67, 100 * experimentPerformance.meanPerformance().getErrorRate(), 2)