DenseFeatures
- class rectools.dataset.features.DenseFeatures(values: ndarray, names: Tuple[str, ...])[source]
Bases:
object
Storage for dense features.
Dense features are represented as a dense matrix, where rows correspond to objects, columns - to features.
Usually you do not need to create this object directly, use from_dataframe class method instead. If you want to use custom logic, use from_iterables class method instead of direct creation.
- Parameters
values (np.ndarray) – Matrix of feature values in the classic format: rows - objects, columns - features.
names (tuple(str)) – Names of features (number of names must be equal to the number of columns in values).
- Inherited-members
Methods
from_dataframe
(df, id_map[, id_col])Create DenseFeatures object from dataframe.
from_iterables
(values, names)Create class instance from any iterables of feature values and names.
Return values in dense format.
Return values in sparse format.
take
(ids)Take a subset of features for given subject (user or item) ids.
Attributes
values
names
- classmethod from_dataframe(df: DataFrame, id_map: IdMap, id_col: str = 'id') DenseFeatures [source]
Create DenseFeatures object from dataframe.
Assume that feature values are values in dataframe, and feature names are column names.
- Parameters
df (pd.Dataframe) – Table in classic format: rows corresponds to objects, columns - to features. One special column id_col must contain object external ids.
id_map (IdMap) – Mapping between external and internal ids. Sets of ids in id_map and in df must be equal.
id_col (str, default
id
) – Name of column containing object ids.
- Return type
- classmethod from_iterables(values: Iterable[Iterable[float]], names: Iterable[str]) DenseFeatures [source]
Create class instance from any iterables of feature values and names.
- Parameters
values (iterable(iterable(float))) – Feature values matrix. E.g. list of lists: [[1, 2, 3], [4, 5, 6]].
names (iterable(str)) – Feature names.
- Return type
- take(ids: Union[Sequence[int], ndarray]) DenseFeatures [source]
Take a subset of features for given subject (user or item) ids.
- Parameters
ids (array-like) – Array of internal ids to select features for.
- Return type