(self)
Calculate clusters using the HDBSCAN library.
Calculate clusters using the HDBSCAN library.
Calculate clusters using the HDBSCAN library .
def scan(self):
        """
        Calculate clusters using the HDBSCAN library.
        """
                
        # Instantiate a HDSCAN object and fit the input data frame:
        self.clusterer = hdbscan.HDBSCAN(**self.hdbscan_kwargs)
        
        # Handle exceptions raised by the fit method with some grace
        try:
            # Scan for clusters
            self.clusterer.fit(self.input_df)
            
            # Prepare the output Data Frame
            self.response = pd.DataFrame(getattr(self.clusterer, self.result_type), index=self.input_df.index, columns=['result'])
            
        except ValueError as e:
            # Prepare output Data Frame if clusters can't be generated
            self.response = pd.DataFrame([-1 for i in range(len(self.request_df))], index=self.input_df.index, columns=['result'])
            
            # Print error message
            self._print_exception('ValueError when scanning for clusters', e)
        
        self.response['key'] = self.input_df.index
        self.response = self.response.loc[:, ['key', 'result']]
        
        # Add the null value rows back to the response
        self.response = self.response.append(pd.DataFrame([('\x00', np.NaN) for i in range(len(self.NaN_df))],\
                                                          columns=self.response.columns))
        
        if self.debug:
            self._print_log(3)
        
        # If the function was called through the load script we return a Data Frame
        if self.load_script:
            self._send_table_description()
            
            return self.response
            
        # If the function was called through a chart expression we return a Series
        else:
            return self.response.loc[:,'result']
def scan ( self ) : # Instantiate a HDSCAN object and fit the input data frame: self . clusterer = hdbscan . HDBSCAN ( * * self . hdbscan_kwargs ) # Handle exceptions raised by the fit method with some grace try : # Scan for clusters self . clusterer . fit ( self . input_df ) # Prepare the output Data Frame self . response = pd . DataFrame ( getattr ( self . clusterer , self . result_type ) , index = self . input_df . index , columns = [ 'result' ] ) except ValueError as e : # Prepare output Data Frame if clusters can't be generated self . response = pd . DataFrame ( [ - 1 for i in range ( len ( self . request_df ) ) ] , index = self . input_df . index , columns = [ 'result' ] ) # Print error message self . _print_exception ( 'ValueError when scanning for clusters' , e ) self . response [ 'key' ] = self . input_df . index self . response = self . response . loc [ : , [ 'key' , 'result' ] ] # Add the null value rows back to the response self . response = self . response . append ( pd . DataFrame ( [ ( '\x00' , np . NaN ) for i in range ( len ( self . NaN_df ) ) ] , columns = self . response . columns ) ) if self . debug : self . _print_log ( 3 ) # If the function was called through the load script we return a Data Frame if self . load_script : self . _send_table_description ( ) return self . response # If the function was called through a chart expression we return a Series else : return self . response . loc [ : , 'result' ]