(self, kwargs)
Set input parameters based on the request.
        :
        :Parameters implemented for the HDBSCAN() function are: algorithm, metric, min_cluster_size, min_samples,
        :p, alpha, cluster_selection_method, allow_single_cluster, match_reference_implementation.
        :More information here: https://hdbscan.readthedocs.io/en/latest/api.html#hdbscan
        :
        :Scaler types implemented for preprocessing data are: StandardScaler, MinMaxScaler, MaxAbsScaler,
        :RobustScaler and QuantileTransformer.
        :More information here: http://scikit-learn.org/stable/modules/preprocessing.html
        :
        :Additional parameters used are: load_script, return, missing, scaler, debug
Set input parameters based on the request.
        :
        :Parameters implemented for the HDBSCAN() function are: algorithm, metric, min_cluster_size, min_samples,
        :p, alpha, cluster_selection_method, allow_single_cluster, match_reference_implementation.
        :More information here: https://hdbscan.readthedocs.io/en/latest/api.html#hdbscan
        :
        :Scaler types implemented for preprocessing data are: StandardScaler, MinMaxScaler, MaxAbsScaler,
        :RobustScaler and QuantileTransformer.
        :More information here: http://scikit-learn.org/stable/modules/preprocessing.html
        :
        :Additional parameters used are: load_script, return, missing, scaler, debug
Set input parameters based on the request . : : Parameters implemented for the HDBSCAN () function are : algorithm metric min_cluster_size min_samples : p alpha cluster_selection_method allow_single_cluster match_reference_implementation . : More information here : https : // hdbscan . readthedocs . io / en / latest / api . html#hdbscan : : Scaler types implemented for preprocessing data are : StandardScaler MinMaxScaler MaxAbsScaler : RobustScaler and QuantileTransformer . : More information here : http : // scikit - learn . org / stable / modules / preprocessing . html : : Additional parameters used are : load_script return missing scaler debug
def _set_params(self, kwargs):
        """
        Set input parameters based on the request.
        :
        :Parameters implemented for the HDBSCAN() function are: algorithm, metric, min_cluster_size, min_samples,
        :p, alpha, cluster_selection_method, allow_single_cluster, match_reference_implementation.
        :More information here: https://hdbscan.readthedocs.io/en/latest/api.html#hdbscan
        :
        :Scaler types implemented for preprocessing data are: StandardScaler, MinMaxScaler, MaxAbsScaler,
        :RobustScaler and QuantileTransformer.
        :More information here: http://scikit-learn.org/stable/modules/preprocessing.html
        :
        :Additional parameters used are: load_script, return, missing, scaler, debug
        """
        
        # Set the row count in the original request
        self.request_row_count = len(self.request_df) + len(self.NaN_df)
        
        # Set default values which will be used if arguments are not passed
        
        # SSE parameters:
        self.load_script = False
        self.result_type = 'labels_'
        self.missing = 'zeros'
        self.scaler = 'robust'
        self.debug = False
        # HDBSCAN parameters:
        self.algorithm = None
        self.metric = None
        self.min_cluster_size = None
        self.min_samples = None
        self.p = None
        self.alpha = None
        self.cluster_selection_method = None
        self.allow_single_cluster = None
        self.match_reference_implementation = None
        # Standard scaler parameters:
        self.with_mean = None
        self.with_std = None
        # MinMaxScaler scaler parameters:
        self.feature_range = None
        # Robust scaler parameters:
        self.with_centering = None
        self.with_scaling = None
        self.quantile_range = None
        # Quantile Transformer parameters:
        self.n_quantiles = None
        self.output_distribution = None
        self.ignore_implicit_zeros = None
        self.subsample = None
        self.random_state = None
        
        # Adjust default options if variant is two_dims
        if self.variant == "two_dims":
            self.load_script = True
        
        # Adjust default options if variant is lat_long
        elif self.variant == "lat_long":
            self.scaler = "none"
            self.metric = "haversine"
        
        # Set optional parameters
        
        # If the key word arguments were included in the request, get the parameters and values
        if len(kwargs) > 0:
            
            # The parameter and values are transformed into key value pairs
            args = kwargs.translate(str.maketrans('', '', string.whitespace)).split(",")
            self.kwargs = dict([arg.split("=") for arg in args])
            
            # Make sure the key words are in lower case
            self.kwargs = {k.lower(): v for k, v in self.kwargs.items()}
            
            # Set the load_script parameter to determine the output format 
            # Set to 'true' if calling the functions from the load script in the Qlik app
            if 'load_script' in self.kwargs:
                self.load_script = 'true' == self.kwargs['load_script'].lower()
            
            # Set the return type 
            # Valid values are: labels, probabilities, cluster_persistence, outlier_scores
            if 'return' in self.kwargs:
                self.result_type = self.kwargs['return'].lower() + '_'
            
            # Set the strategy for missing data
            # Valid values are: zeros, mean, median, mode
            if 'missing' in self.kwargs:
                self.missing = self.kwargs['missing'].lower()
            
            # Set the standardization strategy for the data
            # Valid values are: standard, minmax, maxabs, robust, quantile, none
            if 'scaler' in self.kwargs:
                self.scaler = self.kwargs['scaler'].lower()
            
            # Set the debug option for generating execution logs
            # Valid values are: true, false
            if 'debug' in self.kwargs:
                self.debug = 'true' == self.kwargs['debug'].lower()
            
            # Set optional parameters for the HDBSCAN algorithmn
            # For documentation see here: https://hdbscan.readthedocs.io/en/latest/api.html#id20
            
            # Options are: best, generic, prims_kdtree, prims_balltree, boruvka_kdtree, boruvka_balltree
            # Default is 'best'.
            if 'algorithm' in self.kwargs:
                self.algorithm = self.kwargs['algorithm'].lower()
            
            # The metric to use when calculating distance between instances in a feature array.
            # More information here: https://hdbscan.readthedocs.io/en/latest/basic_hdbscan.html#what-about-different-metrics
            # And here: http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.DistanceMetric.html
            # Default is 'euclidean' for 'standard' and 'two_dims' variants, and 'haversine' for the lat_long variant.
            if 'metric' in self.kwargs:
                self.metric = self.kwargs['metric'].lower()
            
            # The minimum size of clusters. 
            # The default value is 5.
            if 'min_cluster_size' in self.kwargs:
                self.min_cluster_size = utils.atoi(self.kwargs['min_cluster_size'])
                
            # The number of samples in a neighbourhood for a point to be considered a core point.
            if 'min_samples' in self.kwargs:
                self.min_samples = utils.atoi(self.kwargs['min_samples'])
            
            # p value to use if using the minkowski metric.
            if 'p' in self.kwargs:
                self.p = utils.atoi(self.kwargs['p'])
            
            # A distance scaling parameter as used in robust single linkage.
            if 'alpha' in self.kwargs:
                self.alpha = utils.atof(self.kwargs['alpha'])
            
            # The method used to select clusters from the condensed tree.
            # Options are: eom, leaf.
            if 'cluster_selection_method' in self.kwargs:
                self.cluster_selection_method = self.kwargs['cluster_selection_method'].lower()
            
            # By default HDBSCAN* will not produce a single cluster.
            # Setting this to True will override this and allow single cluster results.
            if 'allow_single_cluster' in self.kwargs:
                self.allow_single_cluster = 'true' == self.kwargs['allow_single_cluster'].lower()
            
            # There exist some interpretational differences between this HDBSCAN implementation 
            # and the original authors reference implementation in Java. 
            # Note that there is a performance cost for setting this to True.
            if 'match_reference_implementation' in self.kwargs:
                self.match_reference_implementation = 'true' == self.kwargs['match_reference_implementation']
            
            # Set optional parameters for the scaler functions
            
            # Parameters for the Standard scaler
            # http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html
            if self.scaler == 'standard':
                if 'with_mean' in self.kwargs:
                    self.with_mean = 'true' == self.kwargs['with_mean'].lower()
                if 'with_std' in self.kwargs:
                    self.with_std = 'true' == self.kwargs['with_std'].lower()
            
            # Parameters for the MinMax scaler
            # http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html
            if self.scaler == 'minmax':
                if 'feature_range' in self.kwargs:
                    self.feature_range = ''.join(c for c in self.kwargs['feature_range'] if c not in '()').split(';')
                    self.feature_range = (utils.atoi(self.feature_range[0]),utils.atoi(self.feature_range[1]))
            
            # Parameters for the Robust scaler
            # http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.RobustScaler.html
            if self.scaler == 'robust':
                if 'with_centering' in self.kwargs:
                    self.with_centering = 'true' == self.kwargs['with_centering'].lower()
                if 'with_scaling' in self.kwargs:
                    self.with_scaling = 'true' == self.kwargs['with_scaling'].lower()
                if 'quantile_range' in self.kwargs:
                    self.quantile_range = ''.join(c for c in self.kwargs['quantile_range'] if c not in '()').split(';')
                    self.quantile_range = (utils.atof(self.quantile_range[0]),utils.atof(self.quantile_range[1]))
            
            # Parameters for the Quantile Transformer
            # http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.QuantileTransformer.html
            if self.scaler == 'quantile':
                if 'n_quantiles' in self.kwargs:
                    self.n_quantiles = utils.atoi(self.kwargs['n_quantiles'])
                if 'output_distribution' in self.kwargs:
                    self.output_distribution = self.kwargs['output_distribution'].lower()
                if 'ignore_implicit_zeros' in self.kwargs:
                    self.ignore_implicit_zeros = 'true' == self.kwargs['ignore_implicit_zeros'].lower()
                if 'subsample' in self.kwargs:
                    self.subsample = utils.atoi(self.kwargs['subsample'])
                if 'random_state' in self.kwargs:
                    self.random_state = utils.atoi(self.kwargs['random_state'])
        
        # Set up a list of possible key word arguments for the HDBSCAN() function
        hdbscan_params = ['algorithm', 'metric', 'min_cluster_size', 'min_samples', 'p', 'alpha',\
                          'cluster_selection_method', 'allow_single_cluster', 'match_reference_implementation']
        
        # Create dictionary of key word arguments for the HDBSCAN() function
        self.hdbscan_kwargs = self._populate_dict(hdbscan_params)
               
        # Set up a list of possible key word arguments for the sklearn preprocessing functions
        scaler_params = ['with_mean', 'with_std', 'feature_range', 'with_centering', 'with_scaling',\
                        'quantile_range', 'n_quantiles', 'output_distribution', 'ignore_implicit_zeros',\
                        'subsample', 'random_state']
        
        # Create dictionary of key word arguments for the scaler functions
        self.scaler_kwargs = self._populate_dict(scaler_params)
def _set_params ( self , kwargs ) : # Set the row count in the original request self . request_row_count = len ( self . request_df ) + len ( self . NaN_df ) # Set default values which will be used if arguments are not passed # SSE parameters: self . load_script = False self . result_type = 'labels_' self . missing = 'zeros' self . scaler = 'robust' self . debug = False # HDBSCAN parameters: self . algorithm = None self . metric = None self . min_cluster_size = None self . min_samples = None self . p = None self . alpha = None self . cluster_selection_method = None self . allow_single_cluster = None self . match_reference_implementation = None # Standard scaler parameters: self . with_mean = None self . with_std = None # MinMaxScaler scaler parameters: self . feature_range = None # Robust scaler parameters: self . with_centering = None self . with_scaling = None self . quantile_range = None # Quantile Transformer parameters: self . n_quantiles = None self . output_distribution = None self . ignore_implicit_zeros = None self . subsample = None self . random_state = None # Adjust default options if variant is two_dims if self . variant == "two_dims" : self . load_script = True # Adjust default options if variant is lat_long elif self . variant == "lat_long" : self . scaler = "none" self . metric = "haversine" # Set optional parameters # If the key word arguments were included in the request, get the parameters and values if len ( kwargs ) > 0 : # The parameter and values are transformed into key value pairs args = kwargs . translate ( str . maketrans ( '' , '' , string . whitespace ) ) . split ( "," ) self . kwargs = dict ( [ arg . split ( "=" ) for arg in args ] ) # Make sure the key words are in lower case self . kwargs = { k . lower ( ) : v for k , v in self . kwargs . items ( ) } # Set the load_script parameter to determine the output format  # Set to 'true' if calling the functions from the load script in the Qlik app if 'load_script' in self . kwargs : self . load_script = 'true' == self . kwargs [ 'load_script' ] . lower ( ) # Set the return type  # Valid values are: labels, probabilities, cluster_persistence, outlier_scores if 'return' in self . kwargs : self . result_type = self . kwargs [ 'return' ] . lower ( ) + '_' # Set the strategy for missing data # Valid values are: zeros, mean, median, mode if 'missing' in self . kwargs : self . missing = self . kwargs [ 'missing' ] . lower ( ) # Set the standardization strategy for the data # Valid values are: standard, minmax, maxabs, robust, quantile, none if 'scaler' in self . kwargs : self . scaler = self . kwargs [ 'scaler' ] . lower ( ) # Set the debug option for generating execution logs # Valid values are: true, false if 'debug' in self . kwargs : self . debug = 'true' == self . kwargs [ 'debug' ] . lower ( ) # Set optional parameters for the HDBSCAN algorithmn # For documentation see here: https://hdbscan.readthedocs.io/en/latest/api.html#id20 # Options are: best, generic, prims_kdtree, prims_balltree, boruvka_kdtree, boruvka_balltree # Default is 'best'. if 'algorithm' in self . kwargs : self . algorithm = self . kwargs [ 'algorithm' ] . lower ( ) # The metric to use when calculating distance between instances in a feature array. # More information here: https://hdbscan.readthedocs.io/en/latest/basic_hdbscan.html#what-about-different-metrics # And here: http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.DistanceMetric.html # Default is 'euclidean' for 'standard' and 'two_dims' variants, and 'haversine' for the lat_long variant. if 'metric' in self . kwargs : self . metric = self . kwargs [ 'metric' ] . lower ( ) # The minimum size of clusters.  # The default value is 5. if 'min_cluster_size' in self . kwargs : self . min_cluster_size = utils . atoi ( self . kwargs [ 'min_cluster_size' ] ) # The number of samples in a neighbourhood for a point to be considered a core point. if 'min_samples' in self . kwargs : self . min_samples = utils . atoi ( self . kwargs [ 'min_samples' ] ) # p value to use if using the minkowski metric. if 'p' in self . kwargs : self . p = utils . atoi ( self . kwargs [ 'p' ] ) # A distance scaling parameter as used in robust single linkage. if 'alpha' in self . kwargs : self . alpha = utils . atof ( self . kwargs [ 'alpha' ] ) # The method used to select clusters from the condensed tree. # Options are: eom, leaf. if 'cluster_selection_method' in self . kwargs : self . cluster_selection_method = self . kwargs [ 'cluster_selection_method' ] . lower ( ) # By default HDBSCAN* will not produce a single cluster. # Setting this to True will override this and allow single cluster results. if 'allow_single_cluster' in self . kwargs : self . allow_single_cluster = 'true' == self . kwargs [ 'allow_single_cluster' ] . lower ( ) # There exist some interpretational differences between this HDBSCAN implementation  # and the original authors reference implementation in Java.  # Note that there is a performance cost for setting this to True. if 'match_reference_implementation' in self . kwargs : self . match_reference_implementation = 'true' == self . kwargs [ 'match_reference_implementation' ] # Set optional parameters for the scaler functions # Parameters for the Standard scaler # http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html if self . scaler == 'standard' : if 'with_mean' in self . kwargs : self . with_mean = 'true' == self . kwargs [ 'with_mean' ] . lower ( ) if 'with_std' in self . kwargs : self . with_std = 'true' == self . kwargs [ 'with_std' ] . lower ( ) # Parameters for the MinMax scaler # http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html if self . scaler == 'minmax' : if 'feature_range' in self . kwargs : self . feature_range = '' . join ( c for c in self . kwargs [ 'feature_range' ] if c not in '()' ) . split ( ';' ) self . feature_range = ( utils . atoi ( self . feature_range [ 0 ] ) , utils . atoi ( self . feature_range [ 1 ] ) ) # Parameters for the Robust scaler # http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.RobustScaler.html if self . scaler == 'robust' : if 'with_centering' in self . kwargs : self . with_centering = 'true' == self . kwargs [ 'with_centering' ] . lower ( ) if 'with_scaling' in self . kwargs : self . with_scaling = 'true' == self . kwargs [ 'with_scaling' ] . lower ( ) if 'quantile_range' in self . kwargs : self . quantile_range = '' . join ( c for c in self . kwargs [ 'quantile_range' ] if c not in '()' ) . split ( ';' ) self . quantile_range = ( utils . atof ( self . quantile_range [ 0 ] ) , utils . atof ( self . quantile_range [ 1 ] ) ) # Parameters for the Quantile Transformer # http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.QuantileTransformer.html if self . scaler == 'quantile' : if 'n_quantiles' in self . kwargs : self . n_quantiles = utils . atoi ( self . kwargs [ 'n_quantiles' ] ) if 'output_distribution' in self . kwargs : self . output_distribution = self . kwargs [ 'output_distribution' ] . lower ( ) if 'ignore_implicit_zeros' in self . kwargs : self . ignore_implicit_zeros = 'true' == self . kwargs [ 'ignore_implicit_zeros' ] . lower ( ) if 'subsample' in self . kwargs : self . subsample = utils . atoi ( self . kwargs [ 'subsample' ] ) if 'random_state' in self . kwargs : self . random_state = utils . atoi ( self . kwargs [ 'random_state' ] ) # Set up a list of possible key word arguments for the HDBSCAN() function hdbscan_params = [ 'algorithm' , 'metric' , 'min_cluster_size' , 'min_samples' , 'p' , 'alpha' , 'cluster_selection_method' , 'allow_single_cluster' , 'match_reference_implementation' ] # Create dictionary of key word arguments for the HDBSCAN() function self . hdbscan_kwargs = self . _populate_dict ( hdbscan_params ) # Set up a list of possible key word arguments for the sklearn preprocessing functions scaler_params = [ 'with_mean' , 'with_std' , 'feature_range' , 'with_centering' , 'with_scaling' , 'quantile_range' , 'n_quantiles' , 'output_distribution' , 'ignore_implicit_zeros' , 'subsample' , 'random_state' ] # Create dictionary of key word arguments for the scaler functions self . scaler_kwargs = self . _populate_dict ( scaler_params )