featurevectormatrix package¶
Module contents¶
- class featurevectormatrix.FeatureVectorMatrix(default_value=0, default_to_hashed_rows=False, rows=None)[source]¶
Bases: object
A class to abstract away the differences in internal representation between dictionaries and lists that can matter for very large datasets of vectors and allow them to work seamlessly with each other
Supports indexing and iteration (fvm[1] and for i in fvm:...) but you should set default_to_hash_rows to get the expected behavior. Also supports len
- add_row(list_or_dict, key=None)[source]¶
Adds a list or dict as a row in the FVM data structure
Parameters: - key (str) – key used when rows is a dict rather than an array
- list_or_dict – a feature list or dict
- default_to_hashed_rows(default=None)[source]¶
Gets the current setting with no parameters, sets it if a boolean is passed in
Parameters: default – the value to set Returns: the current value, or new value if default is set to True or False
- extend_rows(list_or_dict)[source]¶
Add multiple rows at once
Parameters: list_or_dict – a 2 dimensional structure for adding multiple rows at once Returns:
- get_matrix()[source]¶
Use numpy to create a real matrix object from the data
Returns: the matrix representation of the fvm
- get_row_dict(row_idx)[source]¶
Return a dictionary representation for a matrix row
Parameters: row_idx – which row Returns: a dict of feature keys/values, not including ones which are the default value
- get_row_list(row_idx)[source]¶
get a feature vector for the nth row
Parameters: row_idx – which row Returns: a list of feature values, ordered by column_names
- keys()[source]¶
Returns all row keys
Raises NotImplementedError: if all rows aren’t keyed Returns: all row keys
- set_column_names(column_names)[source]¶
Setup the feature vector with some column names :param column_names: the column names we want :return: