Example #1
0
class SVMTest(unittest.TestCase):
    def setUp(self):
        self.problem = Problem("BinaryClassification", "../../../examples/data/lin_training.csv")
        self.problem.set_label("Name")
        self.problem.set_model("SVM")
        self.data = self.problem.data
        self.model = self.problem.model

    def tearDown(self):
        self.problem = None
        self.data = None

    def test_fit_stats(self):
        self.model.fit(None)
        acc = calculate_acc(self.model.fit_report['output'], self.model.fit_report['target'])
        self.assertEqual(0.97668, round(acc, 5))
Example #2
0
class ModelUtilTest(unittest.TestCase):
    def setUp(self):
        self.problem = Problem("BinaryClassification", "../../../examples/data/iris.csv")
        self.problem.set_label("Name")
        self.problem.set_model("NaiveBayes")
        self.data = self.problem.data

    def tearDown(self):
        self.problem = None
        self.data = None

    def test_unique_list(self):
        ulist = unique_list(self.data['Name'])
        self.assertEqual(set(['Iris-versicolor', 'Iris-setosa']), set(ulist))

    def test_get_both_columns(self):
        num_cols, cat_cols = get_both_columns(self.data, 'Name')
        self.assertEqual(set(['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth']), set(num_cols))
        self.assertEqual(set(['Dum']), set(cat_cols))

    def test_get_mean_std(self):
        mean, std = get_mean_std(self.data['SepalWidth'])
        self.assertEqual(3.0940, round(mean, 4))
        self.assertEqual(0.4761, round(std, 4))

    def test_calculate_prob(self):
        prob = calculate_prob(10, 2, 3)
        self.assertEqual(0.0038, round(prob, 4))

    def test_nonlin(self):
        out = nonlin(0.5, False)
        self.assertEqual(0.62246, round(out, 5))
        out = nonlin(0.5, True)
        self.assertEqual(0.25, round(out, 5))

    def test_get_class(self):
        x = get_class(0.3)
        self.assertEqual(0, x)

    def test_get_class_np(self):
        x = get_class_np(-0.3)
        self.assertEqual(-1, x)
Example #3
0
class NeuralNetworkTest(unittest.TestCase):
    def setUp(self):
        self.problem = Problem("BinaryClassification", "../../../examples/data/iris.csv")
        self.problem.set_label("Name")
        self.problem.set_model("NeuralNetwork")
        self.data = self.problem.data
        self.model = self.problem.model

    def tearDown(self):
        self.problem = None
        self.data = None

    def test_fit_stats(self):
        self.model.fit()
        acc = calculate_acc(self.model.fit_report['output'], self.model.fit_report['target'])
        self.assertEqual(1.0, acc)

    def test_fit_stats_oneIter(self):
        self.model.num_iter = 1
        self.model.fit()
        acc = calculate_acc(self.model.fit_report['output'], self.model.fit_report['target'])
        self.assertEqual(.5, acc)
Example #4
0
class NaiveBayesTest(unittest.TestCase):
    def setUp(self):
        self.problem = Problem("BinaryClassification", "../../../examples/data/iris.csv")
        self.problem.set_label("Name")
        self.problem.set_model("NaiveBayes")
        self.data = self.problem.data
        self.model = self.problem.model

    def tearDown(self):
        self.problem = None
        self.data = None

    def test_prob_stats(self):
        prob = self.model.prob_hub['Dum']['Iris-versicolor']['a']
        self.assertEqual(0.40, round(prob, 2))

        prob = self.model.prob_hub['Dum']['Iris-setosa']['b']
        self.assertEqual(0.26, round(prob, 2))

    def test_mean_std(self):
        mean, std = get_mean_std(self.data['SepalWidth'])
        self.assertEqual(3.0940, round(mean, 4))
        self.assertEqual(0.4761, round(std, 4))
Example #5
0
class ProblemTest(unittest.TestCase):
    def setUp(self):
        self.problem = Problem("BinaryClassification", "../../../examples/data/iris.csv")
        self.problem.set_label("Name")

    def tearDown(self):
        self.problem = None

    def test_data_read(self):
        self.assertEqual(len(self.problem.data), 100)

    def test_problem_reload(self):
        self.problem.save("test_problem.json", "test_data.json")
        self.problem.load("test_problem.json", "test_data.json")
        self.test_problem_descriptions()

    def test_problem_descriptions(self):
        self.assertEqual(self.problem.label, "Name")
        self.assertEqual(self.problem.problem_type, "BinaryClassification")
        self.assertEqual(self.problem.file_path, "../../../examples/data/iris.csv")
Example #6
0
__author__ = 'Jiarui Xu'

from learnpy.Problem import Problem

# create a problem with training data
pro = Problem("BinaryClassification", "./data/iris_training.csv")

# set the predictor variable
pro.set_label('Name')

# save the problem
pro.save("problem.json", "data.json")
# load the problem
pro.load("problem.json", "data.json")

pro.set_model("SVM")
pro.model.fit(None)

# set testing data
pro.set_testing("./data/iris_testing.csv")
pro.predict()


# new problem for 242 demo

# create a problem
pro2 = Problem("BinaryClassification", "./data/lin_training.csv")

# set the predictor variable
pro2.set_label('Name')
Example #7
0
 def setUp(self):
     self.problem = Problem("BinaryClassification", "../../../examples/data/iris.csv")
     self.problem.set_label("Name")
Example #8
0
 def setUp(self):
     self.problem = Problem("BinaryClassification", "../../../examples/data/iris.csv")
     self.problem.set_label("Name")
     self.problem.set_model("NeuralNetwork")
     self.data = self.problem.data
     self.model = self.problem.model
Example #9
0
__author__ = 'Jiarui Xu'

from learnpy.Problem import Problem

# create a problem
pro = Problem("BinaryClassification", "./data/iris_training.csv")

# set the predictor variable
pro.set_label('Name')

pro.set_model("NaiveBayes")
pro.model.fit(None)

pro.set_testing("./data/iris_testing.csv")
pro.predict()


# new problem

# create a problem
pro2 = Problem("BinaryClassification", "./data/lin_training.csv")

# set the predictor variable
pro2.set_label('Name')

pro2.set_model("NaiveBayes")
pro2.model.fit(None)

pro2.set_testing("./data/lin_testing.csv")
pro2.predict()
Example #10
0
__author__ = 'Jiarui Xu'

from learnpy.Problem import Problem

# create a problem
pro = Problem("BinaryClassification", "./data/iris_training.csv")

# set the predictor variable
pro.set_label('Name')

# use the model neural network
pro.set_model("NeuralNetwork", num_iter=1000)

# fit the model into the data set above
pro.model.fit(None)

# set testing data
pro.set_testing("./data/iris_testing.csv")
pro.predict()
Example #11
0
 def setUp(self):
     self.problem = Problem("BinaryClassification", "../../../examples/data/lin_training.csv")
     self.problem.set_label("Name")
     self.problem.set_model("SVM")
     self.data = self.problem.data
     self.model = self.problem.model