def test_fit_population_sklearn_ko(self):
     """
     Tests the unexpected error, raised by algorithm
     """
     with self.assertRaises(IkatsException):
         fit(population=get_table(),
             target_column_name='"Species"',
             identifier_column_name="Id",
             depth_parameters="0;2;5;3",
             table_name="my_table",
             balanced_parameters="True;False")
 def test_fit_ko_from_bad_folds(self):
     """
     Tests the execution when the user gives bad number of folds
     """
     with self.assertRaises(IkatsInputTypeError):
         fit(population="id",
             target_column_name='"Species"',
             identifier_column_name="Id",
             depth_parameters="0;3;5;4",
             balanced_parameters="True;False",
             table_name="my_table",
             folds=2.4)
 def test_fit_ko_from_bad_balancing(self):
     """
     Tests the execution when the user gives bad balancing parameters
     """
     with self.assertRaises(IkatsException):
         fit(population=get_table(),
             target_column_name='"Species"',
             identifier_column_name="Id",
             depth_parameters="0;3;5;4",
             balanced_parameters="true;false",
             table_name="my_table",
             folds=3)
    def test_fit_from_id_with_param(self):
        """
        Tests the nominal execution based upon mock data: IRIS data
        """

        mdl, dot, best_params, table_name = fit(
            population=get_table(),
            target_column_name='"Species"',
            identifier_column_name="Id",
            depth_parameters="0;2;5;3",
            balanced_parameters="True;False",
            table_name="my_table",
            folds=5)

        cv_res = IkatsApi.table.read(name=table_name)

        # trained: 71,5.9,3.2,4.8,1.8,I. versicolor
        # => test below should obtain same class:
        #
        # mdl.predict([[5.9, 3.2, 4.8, 1.8]]) returns a numpy.ndarray
        # so we have to convert predicted value to str:
        predicted = "{}".format(mdl.predict([[5.9, 3.0, 5.1, 1.8]])[0])
        self.assertEqual(predicted, "I. virginica",
                         "Failed to use the computed model")

        self.assertTrue(type(dot) == str, "Bad type for the dot returned")
        self.assertTrue(
            type(best_params) == str,
            "Bad type for the best parameters returned")
        self.assertTrue(
            type(cv_res) == defaultdict,
            "Bad type for the cross validation results returned")
    def test_fit_nominal_from_id(self):
        """
        Tests the nominal execution based upon mock data: IRIS data
        """

        mdl, dot, best_params, table_name = fit(population=get_table(),
                                                target_column_name='"Species"',
                                                table_name="my_table",
                                                identifier_column_name="Id")

        cv_res = IkatsApi.table.read(name=table_name)

        # trained: 71,5.9,3.2,4.8,1.8,I. versicolor
        # => test below should obtain same class:
        #
        # mdl.predict([[5.9, 3.2, 4.8, 1.8]]) returns a numpy.ndarray
        # so we have to convert predicted value to str:
        for value, ref_predict in [[[5.9, 3.2, 4.8, 1.8], "I. versicolor"],
                                   [[
                                       5.7,
                                       2.8,
                                       4.1,
                                       1.3,
                                   ], "I. versicolor"],
                                   [[5.9, 3.0, 5.1, 1.8], "I. virginica"]]:
            predicted = "{}".format(mdl.predict([value])[0])
            self.assertEqual(
                predicted, ref_predict,
                "Failed to use the computed model: predict x={}".format(value))

        self.assertTrue(type(dot) == str, "Bad type for the dot returned")
        self.assertTrue(
            type(best_params) == str,
            "Bad type for the best parameters returned")
        self.assertTrue(
            type(cv_res) == defaultdict,
            "Bad type for the cross validation results returned")