コード例 #1
0
    def __init__(self, splitrule="Logrank", num_trees=10):

        # Checking the format of num_trees
        if not (isinstance(num_trees, int) or isinstance(num_trees, float)):
            error = '{} is not a valid value for "num_trees" '
            error += 'as "num_trees" is a positive integer'.format(num_trees)
            raise ValueError(error)
        if num_trees <= 0:
            error = '{} is not a valid value for "num_trees" '
            error += 'as "num_trees" is a positive integer'.format(num_trees)
            raise ValueError(error)
        self.num_trees = num_trees

        # Checking the format of splitrule
        if SPLITTING_RULES.get(splitrule.lower()) is None:
            error = '{} is not a valid splitrule method. Choose between '
            error += '"' + '", "'.join(SPLITTING_RULES) + '"'
            error = error.format(splitrule)
            raise ValueError(error)
        self.splitrule = splitrule

        # Initializing the inner model
        self.model = _SurvivalForestModel()

        # Initializing the elements from BaseModel
        super(BaseSurvivalForest, self).__init__(auto_scaler=False)
コード例 #2
0
    def load(self, path_file):
        """ Load the model parameters from a zip file into a C++ external
            model 
        """

        # Loading the model
        super(BaseSurvivalForest, self).load(path_file)

        # Re-introduce the C++ object
        self.model = _SurvivalForestModel()
        self.load_properties()
コード例 #3
0
    def save(self, path_file):
        """ Save the model parameters of the model and compress them into 
            a zip file
        """

        # Ensuring the file has the proper name
        folder_name = os.path.dirname(path_file) + '/'
        file_name = os.path.basename(path_file)

        # Checking if the folder is accessible
        if not os.access(folder_name, os.W_OK):
            error_msg = '{} is not an accessible directory.'.format(
                folder_name)
            raise OSError(error_msg)

        # Delete the C++ object before saving
        del self.model

        # Saving the model
        super(BaseSurvivalForest, self).save(path_file)

        # Re-introduce the C++ object
        self.model = _SurvivalForestModel()
        self.load_properties()