Ejemplo n.º 1
0
    def save(self, path_file):
        """ Save the model paremeters of the model (.params) 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(SurvivalSVMModel, self).save(path_file)

        # Re-introduce the C++ object
        self.model = _SVMModel(self.kernel_type, self.scale, self.offset,
                               self.degree)
        self.load_properties()
Ejemplo n.º 2
0
    def load(self, path_file):
        """ Load the model parameters from a zip file into a C++ external
            model 
        """
        # Loading the model
        super(SurvivalSVMModel, self).load(path_file)

        # Re-introduce the C++ object
        self.model = _SVMModel(self.kernel_type, self.scale, self.offset,
                               self.degree)
        self.load_properties()
Ejemplo n.º 3
0
    def __init__(self,
                 kernel="linear",
                 scale=1.,
                 offset=0.,
                 degree=1.,
                 auto_scaler=True):

        # Ensuring that the provided kernel is available
        valid_kernel = [key for key in KERNELS.keys() \
                        if kernel.lower().replace('_', ' ') in key.lower().replace('_', ' ')]

        if len(valid_kernel) == 0:
            raise NotImplementedError(
                '{} is not a valid kernel function.'.format(kernel))
        else:
            kernel_type = KERNELS[valid_kernel[0]]
            kernel = valid_kernel[0]

        # Checking the kernel parameters
        if not (degree >= 0. and
                (isinstance(degree, float) or isinstance(degree, int))):
            error = "degree parameter is not valid. degree is a >= 0 value"
            raise ValueError(error)

        if not (isinstance(scale, float) or isinstance(scale, int)):
            error = "scale parameter is not valid."
            raise ValueError(error)

        if not (isinstance(offset, float) or isinstance(offset, int)):
            error = "offset parameter is not valid."
            raise ValueError(error)

        # Saving the attributes
        self.kernel = kernel
        self.kernel_type = kernel_type
        self.scale = scale
        self.offset = offset
        self.degree = degree

        # Initializing the C++ object
        self.model = _SVMModel(self.kernel_type, self.scale, self.offset,
                               self.degree)

        # Initializing the elements from BaseModel
        super(SurvivalSVMModel, self).__init__(auto_scaler)