cli/streamingphish/streamingphish/features.py
def compute_features(self, fqdns, values_only=True):
        """
        Calls all the methods in this class that begin with '_fe_'. Not sure how pythonic
        this is, but I wanted dynamic functions so those can be written without having
        to manually define them here. Shooting for how python's unittest module works,
        there's a chance this is a python crime.

        Args:
            fqdns (list): fqdns to compute features for.
            values_only (boolean, optional): Instead computes a np array w/ values only
                and returns that instead of a list of dictionaries (reduces perf overhead).

        Returns:
            result (dict): 'values' will always be returned - list of feature values of
                each FQDN being analyzed. Optional key included is 'names', which is the
                feature vector and will be returned if values_only=True.
        """
        result = {}

        # Raw features are a list of dictionaries, where keys = feature names and
        # values = feature values.
        features = []
        for fqdn in fqdns:
            sample = self._fqdn_parts(fqdn=fqdn)
            sample['fqdn'] = self._remove_common_hosts(fqdn=fqdn)
            sample['fqdn_words'] = re.split('\W+', fqdn)

            analysis = OrderedDict()
            for item in dir(self):
                if item.startswith('_fe_'):
                    method = getattr(self, item)
                    result = method(sample)
                    analysis = {**analysis, **result}
            # Must sort dictionary by key before adding.
            analysis = OrderedDict(sorted(analysis.items()))
            features.append(analysis)

        # Split out keys and values from list of dictionaries. Keys = feature names, and
        # values = feature values.
        result = {}
        result['values'] = []
        for item in features:
            result['values'].append(np.fromiter(item.values(), dtype=float))

        if not values_only:
            # Take the dictionary keys from the first item - this is the feature vector.
            result['names'] = features[0].keys()

        return result

        Calls all the methods in this class that begin with '_fe_'. Not sure how pythonic
        this is, but I wanted dynamic functions so those can be written without having
        to manually define them here. Shooting for how python's unittest module works,
        there's a chance this is a python crime.

        Args:
            fqdns (list): fqdns to compute features for.
            values_only (boolean, optional): Instead computes a np array w/ values only
                and returns that instead of a list of dictionaries (reduces perf overhead).

        Returns:
            result (dict): 'values' will always be returned - list of feature values of
                each FQDN being analyzed. Optional key included is 'names', which is the
                feature vector and will be returned if values_only=True.
        
Calls all the methods in this class that begin with '_fe_'. Not sure how pythonic
this is, but I wanted dynamic functions so those can be written without having
to manually define them here. Shooting for how python's unittest module works,
there's a chance this is a python crime.
Calls all the methods in this class that begin with ' _fe_ ' . Not sure how pythonic this is but I wanted dynamic functions so those can be written without having to manually define them here . Shooting for how python ' s unittest module works there ' s a chance this is a python crime .
def compute_features(self, fqdns, values_only=True):
        result = {}
        features = []
        for fqdn in fqdns:
            sample = self._fqdn_parts(fqdn=fqdn)
            sample['fqdn'] = self._remove_common_hosts(fqdn=fqdn)
            sample['fqdn_words'] = re.split('\W+', fqdn)
            analysis = OrderedDict()
            for item in dir(self):
                if item.startswith('_fe_'):
                    method = getattr(self, item)
                    result = method(sample)
                    analysis = {**analysis, **result}
            analysis = OrderedDict(sorted(analysis.items()))
            features.append(analysis)
        result = {}
        result['values'] = []
        for item in features:
            result['values'].append(np.fromiter(item.values(), dtype=float))
        if not values_only:
            result['names'] = features[0].keys()
        return result
def compute_features ( self , fqdns , values_only = True ) : result = { } features = [ ] for fqdn in fqdns : sample = self . _fqdn_parts ( fqdn = fqdn ) sample [ 'fqdn' ] = self . _remove_common_hosts ( fqdn = fqdn ) sample [ 'fqdn_words' ] = re . split ( '\W+' , fqdn ) analysis = OrderedDict ( ) for item in dir ( self ) : if item . startswith ( '_fe_' ) : method = getattr ( self , item ) result = method ( sample ) analysis = { ** analysis , ** result } analysis = OrderedDict ( sorted ( analysis . items ( ) ) ) features . append ( analysis ) result = { } result [ 'values' ] = [ ] for item in features : result [ 'values' ] . append ( np . fromiter ( item . values ( ) , dtype = float ) ) if not values_only : result [ 'names' ] = features [ 0 ] . keys ( ) return result
Calls all the methods in this class that begin with '_fe_'.
Calls all the methods in this class that begin with ' _fe_ ' .
"""
        Calls all the methods in this class that begin with '_fe_'. Not sure how pythonic
        this is, but I wanted dynamic functions so those can be written without having
        to manually define them here. Shooting for how python's unittest module works,
        there's a chance this is a python crime.

        Args:
            fqdns (list): fqdns to compute features for.
            values_only (boolean, optional): Instead computes a np array w/ values only
                and returns that instead of a list of dictionaries (reduces perf overhead).

        Returns:
            result (dict): 'values' will always be returned - list of feature values of
                each FQDN being analyzed. Optional key included is 'names', which is the
                feature vector and will be returned if values_only=True.
        """ # Raw features are a list of dictionaries, where keys = feature names and # values = feature values. # Must sort dictionary by key before adding. # Split out keys and values from list of dictionaries. Keys = feature names, and # values = feature values. # Take the dictionary keys from the first item - this is the feature vector.
result (dict): 'values' will always be returned - list of feature values of
each FQDN being analyzed. Optional key included is 'names', which is the
feature vector and will be returned if values_only=True.
result ( dict ) : ' values ' will always be returned - list of feature values of each FQDN being analyzed . Optional key included is ' names ' which is the feature vector and will be returned if values_only = True .
self
fqdns
fqdns to compute features for.
fqdns to compute features for .
values_only
Instead computes a np array w/ values only
and returns that instead of a list of dictionaries (reduces perf overhead).
Instead computes a np array w / values only and returns that instead of a list of dictionaries ( reduces perf overhead ) .