示例#1
0
    def test_scenario1(self):
        """
            Scenario: Successfully creating a prediction from a local model in a json file:
                Given I create a local model from a "<model>" file
                When I create a local prediction for "<data_input>" with confidence
                Then the local prediction is "<prediction>"
                And the local prediction's confidence is "<confidence>"

                Examples:
                | model                | data_input    |  prediction  | confidence
                | ../data/iris_model.json | {"petal length": 0.5} | Iris-setosa | 0.90594

        """
        print self.test_scenario1.__doc__
        examples = [[
            'data/iris_model.json', '{"petal length": 0.5}', 'Iris-setosa',
            '0.90594'
        ],
                    [
                        'data/iris_model.json', '{"petal length": "0.5"}',
                        'Iris-setosa', '0.90594'
                    ]]
        for example in examples:
            print "\nTesting with:\n", example
            prediction_compare.i_create_a_local_model_from_file(
                self, example[0])
            prediction_compare.i_create_a_local_prediction_with_confidence(
                self, example[1])
            prediction_compare.the_local_prediction_is(self, example[2])
            prediction_compare.the_local_prediction_confidence_is(
                self, example[3])
    def test_scenario13(self):
        """
            Scenario: Successfully comparing predictions:
                Given I create a data source uploading a "<data>" file
                And I wait until the source is ready less than <time_1> secs
                And I create a dataset
                And I wait until the dataset is ready less than <time_2> secs
                And I create a model
                And I wait until the model is ready less than <time_3> secs
                And I create a local model
                When I create a prediction for "<data_input>"
                Then the prediction for "<objective>" is "<prediction>"
                And I create a local prediction for "<data_input>"
                Then the local prediction is "<prediction>"

                Examples:
                | data             | time_1  | time_2 | time_3 | data_input                             | objective | prediction  |

        """
        examples = [
            ['data/iris.csv', '10', '10', '10', '{"petal width": 0.5}', '000004', 'Iris-setosa', "tmp/my_model.json", "my_test"],
            ['data/iris.csv', '10', '10', '10', '{"petal length": 6, "petal width": 2}', '000004', 'Iris-virginica', "tmp/my_model.json", "my_test"],
            ['data/iris.csv', '10', '10', '10', '{"petal length": 4, "petal width": 1.5}', '000004', 'Iris-versicolor', "tmp/my_model.json", "my_test"],
            ['data/iris_sp_chars.csv', '10', '10', '10', '{"pétal.length": 4, "pétal&width\u0000": 1.5}', '000004', 'Iris-versicolor', "tmp/my_model.json", "my_test"]]
        show_doc(self.test_scenario13, examples)
        for example in examples:
            print "\nTesting with:\n", example
            source_create.i_upload_a_file(self, example[0])
            source_create.the_source_is_finished(self, example[1])
            dataset_create.i_create_a_dataset(self)
            dataset_create.the_dataset_is_finished_in_less_than(self, example[2])
            args = '{"tags": ["%s"]}' % example[8]
            model_create.i_create_a_model_with(self, data=args)
            model_create.the_model_is_finished_in_less_than(self, example[3])
            model_create.i_export_model(self, False, example[7]) # no pmml
            prediction_compare.i_create_a_local_model_from_file(self, example[7])
            prediction_create.i_create_a_prediction(self, example[4])
            prediction_create.the_prediction_is(self, example[5], example[6])
            prediction_compare.i_create_a_local_prediction(self, example[4])
            prediction_compare.the_local_prediction_is(self, example[6])
            model_create.i_export_tags_model(self, example[7], example[8])
            prediction_compare.i_create_a_local_model_from_file(self, example[7])
            prediction_compare.i_create_a_local_prediction(self, example[4])
            prediction_compare.the_local_prediction_is(self, example[6])
    def test_scenario13(self):
        """
            Scenario: Successfully comparing predictions:
                Given I create a data source uploading a "<data>" file
                And I wait until the source is ready less than <time_1> secs
                And I create a dataset
                And I wait until the dataset is ready less than <time_2> secs
                And I create a model
                And I wait until the model is ready less than <time_3> secs
                And I create a local model
                When I create a prediction for "<data_input>"
                Then the prediction for "<objective>" is "<prediction>"
                And I create a local prediction for "<data_input>"
                Then the local prediction is "<prediction>"

                Examples:
                | data             | time_1  | time_2 | time_3 | data_input                             | objective | prediction  |

        """
        examples = [
            ['data/iris.csv', '10', '10', '10', '{"petal width": 0.5}', '000004', 'Iris-setosa', "tmp/my_model.json", "my_test"],
            ['data/iris.csv', '10', '10', '10', '{"petal length": 6, "petal width": 2}', '000004', 'Iris-virginica', "tmp/my_model.json", "my_test"],
            ['data/iris.csv', '10', '10', '10', '{"petal length": 4, "petal width": 1.5}', '000004', 'Iris-versicolor', "tmp/my_model.json", "my_test"],
            ['data/iris_sp_chars.csv', '10', '10', '10', '{"pétal.length": 4, "pétal&width\u0000": 1.5}', '000004', 'Iris-versicolor', "tmp/my_model.json", "my_test"]]
        show_doc(self.test_scenario13, examples)
        for example in examples:
            print "\nTesting with:\n", example
            source_create.i_upload_a_file(self, example[0])
            source_create.the_source_is_finished(self, example[1])
            dataset_create.i_create_a_dataset(self)
            dataset_create.the_dataset_is_finished_in_less_than(self, example[2])
            args = '{"tags": ["%s"]}' % example[8]
            model_create.i_create_a_model_with(self, data=args)
            model_create.the_model_is_finished_in_less_than(self, example[3])
            model_create.i_export_model(self, False, example[7]) # no pmml
            prediction_compare.i_create_a_local_model_from_file(self, example[7])
            prediction_create.i_create_a_prediction(self, example[4])
            prediction_create.the_prediction_is(self, example[5], example[6])
            prediction_compare.i_create_a_local_prediction(self, example[4])
            prediction_compare.the_local_prediction_is(self, example[6])
            model_create.i_export_tags_model(self, example[7], example[8])
            prediction_compare.i_create_a_local_model_from_file(self, example[7])
            prediction_compare.i_create_a_local_prediction(self, example[4])
            prediction_compare.the_local_prediction_is(self, example[6])
    def test_scenario2(self):
        """
            Scenario: Successfully creating a multiple prediction from a local model in a json file:
                Given I create a local model from a "<model>" file
                When I create a multiple local prediction for "<data_input>"
                Then the multiple local prediction is "<prediction>"

                Examples:
                | model                | data_input    | prediction
                | ../data/iris_model.json | {"petal length": 3} |  [{"count": 42, "confidence": 0.4006020980792863, "prediction": "Iris-versicolor", "probability": 0.5060240963855421}, {"count": 41, "confidence": 0.3890868795664999, "prediction": "Iris-virginica", "probability": 0.4939759036144578}]
        """
        print self.test_scenario1.__doc__
        examples = [
            ['data/iris_model.json', '{"petal length": 3}',  '[{"count": 42, "confidence": 0.4006020980792863, "prediction": "Iris-versicolor", "probability": 0.5060240963855421}, {"count": 41, "confidence": 0.3890868795664999, "prediction": "Iris-virginica", "probability": 0.4939759036144578}]']]
        for example in examples:
            print "\nTesting with:\n", example
            prediction_compare.i_create_a_local_model_from_file(self, example[0])
            prediction_compare.i_create_a_multiple_local_prediction(self, example[1])
            prediction_compare.the_multiple_local_prediction_is(self, example[2])
    def test_scenario1(self):
        """
            Scenario: Successfully creating a prediction from a local model in a json file:
                Given I create a local model from a "<model>" file
                When I create a local prediction for "<data_input>" with confidence
                Then the local prediction is "<prediction>"
                And the local prediction's confidence is "<confidence>"

                Examples:
                | model                | data_input    |  prediction  | confidence
                | ../data/iris_model.json | {"petal length": 0.5} | Iris-setosa | 0.90594

        """
        print self.test_scenario1.__doc__
        examples = [
            ['data/iris_model.json', '{"petal length": 0.5}', 'Iris-setosa', '0.90594']]
        for example in examples:
            print "\nTesting with:\n", example
            prediction_compare.i_create_a_local_model_from_file(self, example[0])
            prediction_compare.i_create_a_local_prediction_with_confidence(self, example[1])
            prediction_compare.the_local_prediction_is(self, example[2])
            prediction_compare.the_local_prediction_confidence_is(self, example[3])