Exemplo n.º 1
0
    def test_create_duplicate_kmeans_model(self):
        model_name = str(uuid.uuid1()).replace('-', '_')

        ta.KMeansModel(name=model_name)
        self.assertTrue(model_name in ta.get_model_names(),
                        model_name + " should be in the list of models")

        # try to create another model with the same name (we expect an exception)
        with self.assertRaises(Exception):
            ta.KMeansModel(name=model_name)
Exemplo n.º 2
0
    def test_duplicate_model_rename(self):
        model_name1 = str(uuid.uuid1()).replace('-', '_')
        model_name2 = str(uuid.uuid1()).replace('-', '_')
        graph_name = str(uuid.uuid1()).replace('-', '_')
        frame_name = str(uuid.uuid1()).replace('-', '_')

        # Create models, graph, and frame to test with
        model1 = ta.KMeansModel(name=model_name1)
        model2 = ta.KMeansModel(name=model_name2)
        ta.Graph(name=graph_name)
        ta.Frame(name=frame_name)

        # After creating models, check that models with each name exists on the server
        self.assertTrue(model_name1 in ta.get_model_names(),
                        model_name1 + " should exist in list of models")
        self.assertTrue(model_name2 in ta.get_model_names(),
                        model_name2 + " should exist in list of models")

        # Try to rename model2 to have the same name as model1 (we expect an exception here)
        with self.assertRaises(Exception):
            model2.name = model_name1

        # Both model names should still exist on the server
        self.assertTrue(model_name1 in ta.get_model_names(),
                        model_name1 + " should still exist in list of models")
        self.assertTrue(model_name2 in ta.get_model_names(),
                        model_name2 + " should still exist in list of models")

        # Try to rename model1 to have the same name as the graph (we expect an exception here)
        with self.assertRaises(Exception):
            model1.name = graph_name

        # model1 and the graph should still exist on the server
        self.assertTrue(
            model_name1 in ta.get_model_names(),
            model_name1 + " should still exist in the list of models")
        self.assertTrue(
            graph_name in ta.get_graph_names(),
            graph_name + " should still exist in the list of graphs")

        # Try to rename model1 to have the same name as the frame (we expect an exception here)
        with self.assertRaises(Exception):
            model1.name = frame_name

        # model1 and the frame should still exist on the server
        self.assertTrue(
            model_name1 in ta.get_model_names(),
            model_name1 + " should still exist in the list of models")
        self.assertTrue(
            frame_name in ta.get_frame_names(),
            frame_name + " should still exist in the list of frames")
Exemplo n.º 3
0
    def test_model(self):
        print "Initialize KMeansModel object with name"
        k1 = ta.KMeansModel(name='smoke_kmeans_model')
        name = k1.name

        print "Initialize KMeansModel object"
        k2 = ta.KMeansModel()

        print "Initialize LogisticRegressionModel object with name"
        l1 = ta.LogisticRegressionModel(name='myLogisticRegressionModel1')

        print "Initialize LogisticRegressionModel object"
        l2 = ta.LogisticRegressionModel()

        print "Initialize NaiveBayesModel object"
        n = ta.NaiveBayesModel()
Exemplo n.º 4
0
    def test_model(self):
        print "Initialize KMeansModel object"
        k = ta.KMeansModel()

        print "Initialize LogisticRegressionModel object"
        l = ta.LogisticRegressionModel()

        print "Initialize NaiveBayesModel object"
        n = ta.NaiveBayesModel()
Exemplo n.º 5
0
    def test_drop_model_by_object(self):
        model_name = str(uuid.uuid1()).replace('-','_')

        # Create model and verify that it's in the get_model_names() list
        model = ta.KMeansModel(name=model_name)
        self.assertTrue(model_name in ta.get_model_names(), model_name + " should exist in the list of models")

        # Drop model using the model object
        self.assertEqual(1, ta.drop_models(model), "drop_models() should have deleted one model.")
        self.assertFalse(model_name in ta.get_model_names(), model_name + " should not exist in the list of models")
Exemplo n.º 6
0
    def test_generic_drop_by_name(self):
        model_name =  str(uuid.uuid1()).replace('-','_')

        ta.KMeansModel(name=model_name)
        self.assertTrue(model_name in ta.get_model_names(), model_name + " should exist in the list of model names")

        # drop() item by name
        self.assertEqual(1, ta.drop(model_name), "drop() should have deleted one item")

        # check that the model no longer exists
        self.assertFalse(model_name in ta.get_model_names(), model_name + " should not exist in the list of models")
Exemplo n.º 7
0
    def test_create_kmeans_model_with_duplicte_graph_name(self):
        graph_name = str(uuid.uuid1()).replace('-', '_')

        # Create graph
        ta.Graph(name=graph_name)
        self.assertTrue(graph_name in ta.get_graph_names(),
                        graph_name + " should be in the list of graphs")

        # Try to create a model with the same name as the graph (we expect an exception)
        with self.assertRaises(Exception):
            ta.KMeansModel(name=graph_name)
Exemplo n.º 8
0
    def test_create_kmeans_model_with_duplicte_frame_name(self):
        frame_name = str(uuid.uuid1()).replace('-', '_')

        # Create frame
        ta.Frame(name=frame_name)
        self.assertTrue(frame_name in ta.get_frame_names(),
                        frame_name + " should be in the list of frames")

        # Try to create model with the same name as the frame (we expect an exception)
        with self.assertRaises(Exception):
            ta.KMeansModel(name=frame_name)
Exemplo n.º 9
0
    def test_kmeans_train_publish(self):

        frame = ta.Frame(
            ta.UploadRows(
                [[2, "ab"], [1, "cd"], [7, "ef"], [1, "gh"], [9, "ij"],
                 [2, "kl"], [0, "mn"], [6, "op"], [5, "qr"]],
                [("data", ta.float64), ("name", str)]))
        model = ta.KMeansModel()
        train_output = model.train(frame, ["data"], [1], 3)
        self.assertTrue(
            train_output.has_key('within_set_sum_of_squared_error'))
        model.publish()
Exemplo n.º 10
0
    def test_generic_drop_by_object(self):
        model_name =  str(uuid.uuid1()).replace('-','_')

        model = ta.KMeansModel(name=model_name)

        # Check that the model we just created now exists
        self.assertTrue(model_name in ta.get_model_names(), model_name + " should exist in the list of model names")

        # drop by entity
        self.assertEqual(1, ta.drop(model), "drop() should have deleted one item")

        # check that the model no longer exists
        self.assertFalse(model_name in ta.get_model_names(), model_name + " should not exist in the list of models")
Exemplo n.º 11
0
    def test_model_rename(self):
        model_name = str(uuid.uuid1()).replace('-', '_')
        new_model_name = str(uuid.uuid1()).replace('-', '_')

        model = ta.KMeansModel(name=model_name)
        self.assertTrue(model_name in ta.get_model_names(),
                        model_name + " should be in the list of models")

        model.name = new_model_name

        self.assertTrue(new_model_name in ta.get_model_names(),
                        new_model_name + " should be in list of models")
        self.assertFalse(model_name in ta.get_model_names(),
                         model_name + " shoule not be in list of models")
Exemplo n.º 12
0
    def testKMeans(self):
        print "define csv file"
        csv = ta.CsvFile("/datasets/KMeansTestFile.csv",
                         schema=[('data', ta.float64), ('name', str)],
                         skip_header_lines=1)

        print "create frame"
        frame = ta.Frame(csv)

        print "Initializing a KMeansModel object"
        k = ta.KMeansModel(name='myKMeansModel')

        print "Training the model on the Frame"
        k.train(frame, ['data'], [2.0])
Exemplo n.º 13
0
    def testKMeans(self):
        """basic KMeans train + piggyback model last_read_date"""
        print "define csv file"
        csv = ta.CsvFile("/datasets/KMeansTestFile.csv", schema= [('data', ta.float64),
                                                             ('name', str)], skip_header_lines=1)

        print "create frame"
        frame = ta.Frame(csv)

        print "Initializing a KMeansModel object"
        k = ta.KMeansModel(name='myKMeansModel')
        t0 = k.last_read_date
        t1 = k.last_read_date
        #print "t0=%s" % t0.isoformat()
        self.assertEqual(t0, t1)

        print "Training the model on the Frame"
        k.train(frame,['data'],[2.0])
        t2 = k.last_read_date
        self.assertLess(t1, t2)