def test3_duplicated_parameter_specification(self):
        """
        This function will randomly choose a parameter in hyper_parameters and specify it as a parameter in the
        model.  Depending on the random error_number generated, the following is being done to the model parameter
        and hyper-parameter:

        error_number = 0: set model parameter to be  a value in the hyper-parameter value list, should
        generate error;
        error_number = 1: set model parameter to be default value, should not generate error in this case;
        error_number = 2: make sure model parameter is not set to default and choose a value not in the
        hyper-parameter value list.

        :return: None
        """
        print("*******************************************************************************************")
        print("test3_duplicated_parameter_specification for GLM " + self.family)

        error_number = np.random.random_integers(0, 2, 1)   # randomly choose an error

        print("error_number is {0}".format(error_number[0]))

        params_dict, error_hyper_params = \
            pyunit_utils.generate_redundant_parameters(self.hyper_params, self.gridable_parameters,
                                                       self.gridable_defaults, error_number[0])

        params_dict["family"] = self.family
        params_dict["nfolds"] = self.nfolds

        print("Your hyper-parameter dict is: ")
        print(error_hyper_params)
        print("Your model parameters are: ")
        print(params_dict)

        # copied from Eric to catch execution run errors and not quit
        try:
            grid_model = H2OGridSearch(H2OGeneralizedLinearEstimator(**params_dict),
                                       hyper_params=error_hyper_params)
            grid_model.train(x=self.x_indices, y=self.y_index, training_frame=self.training1_data)

            # if error_number = 1, it is okay.  Else it should fail.
            if not (error_number[0] == 1):
                self.test_failed += 1
                self.test_failed_array[self.test_num] = 1
                print("test3_duplicated_parameter_specification failed: Java error exception should have been "
                      "thrown but did not!")
            else:
                print("test3_duplicated_parameter_specification passed: Java error exception should not have "
                      "been thrown and did not!")
        except:
            if error_number[0] == 1:
                self.test_failed += 1
                self.test_failed_array[self.test_num] = 1
                print("test3_duplicated_parameter_specification failed: Java error exception should not "
                      "have been thrown! ")
            else:
                print("test3_duplicated_parameter_specification passed: Java error exception should "
                      "have been thrown and did.")
示例#2
0
    def test3_duplicated_parameter_specification(self):
        """
        This function will randomly choose a parameter in hyper_parameters and specify it as a parameter in the
        model.  Depending on the random error_number generated, the following is being done to the model parameter
        and hyper-parameter:

        error_number = 0: set model parameter to be  a value in the hyper-parameter value list, should
        generate error;
        error_number = 1: set model parameter to be default value, should not generate error in this case;
        error_number = 2: make sure model parameter is not set to default and choose a value not in the
        hyper-parameter value list.

        :return: None
        """
        print("*******************************************************************************************")
        print("test3_duplicated_parameter_specification for GLM " + self.family)

        error_number = np.random.random_integers(0, 2, 1)   # randomly choose an error

        params_dict, error_hyper_params = \
            pyunit_utils.generate_redundant_parameters(self.hyper_params, self.gridable_parameters,
                                                       self.gridable_defaults, error_number[0])

        params_dict["family"] = self.family
        params_dict["nfolds"] = self.nfolds

        print("Your hyper-parameter dict is: ")
        print(error_hyper_params)
        print("Your model parameters are: ")
        print(params_dict)

        # copied from Eric to catch execution run errors and not quit
        try:
            if "max_runtime_secs" in list(params_dict):     # need to set max_runtime_secs when calling train
                max_runtime_secs = params_dict["max_runtime_secs"]
                del params_dict["max_runtime_secs"]

                grid_model = H2OGridSearch(H2OGeneralizedLinearEstimator(**params_dict),
                                           hyper_params=error_hyper_params)
                grid_model.train(x=self.x_indices, y=self.y_index, training_frame=self.training1_data,
                                 max_runtime_secs=max_runtime_secs)
            else:
                grid_model = H2OGridSearch(H2OGeneralizedLinearEstimator(**params_dict),
                                           hyper_params=error_hyper_params)
                grid_model.train(x=self.x_indices, y=self.y_index, training_frame=self.training1_data)

            # if error_number = 1, it is okay.  Else it should fail.
            if not (error_number[0] == 1):
                self.test_failed += 1
                self.test_failed_array[self.test_num] = 1
                print("test3_duplicated_parameter_specification failed: Java error exception should have been "
                      "thrown but did not!")
            else:
                print("test3_duplicated_parameter_specification passed: Java error exception should not have "
                      "been thrown and did not!")
        except:
            if error_number[0] == 1:
                self.test_failed += 1
                self.test_failed_array[self.test_num] = 1
                print("test3_duplicated_parameter_specification failed: Java error exception should not "
                      "have been thrown! ")
            else:
                print("test3_duplicated_parameter_specification passed: Java error exception should "
                      "have been thrown and did.")