lenskit / lenskit/lkpy

Add category matrix support to AttributeSet

Open
#892 0 comments 0 reactions 2 assignees View on GitHub

@sushobhan2024 is already working on this.

Since Oct 16, 2025.

data
Dominant language
Python
Stars
314
Forks
77
Avg merge
4d 6m
Merged PRs (30d)
10

Description

As discussed today with @sushobhan2024, we need to add a new cat_matrix method to AttributeSet and its subclasses, to compute a matrix over categorical values for various attribute representations.

  • Define the cat_matrix signature. Proposed:

    def cat_matrix(self, *, normalize: Literal["unit" | "distribution"] = None) -> NDArray[np.floating[Any]] | csr_array: ...
    
  • Implement cat_matrix for scalar attribute sets, where the columns of the matrix refer to distinct values of the attribute. It should throw a TypeError if the attribute is floating-point. We may want to cache a Vocabulary of distinct values to speed up repeated calls. If the attribute is null for a given item, the resulting matrix should be all 0. Should usually return a sparse matrix (csr_array).

  • Implement cat_matrix for list attribute sets. Behaves like scalar attribute, except that more than one value can be nonzero.

  • Implement cat_matrix for dense vector attribute sets. Returns a dense matrix (np.ndarray), columns correspond to the attribute vector columns. Basically just returns the vector as-is, possibly with normalized rows.

  • Implement cat_matrix for sparse vector attribute sets. Same as dense, except it returns a sparse matrix instead of a dense one.

Open question: do we provide access to the vocabulary for list and scalar attribute sets, and how? Maybe we also add a cat_vocabulary() method that returns the column vocabulary for a vector attribute set, and the unique value vocabulary for a scalar or list set, and None if the scalar or list is floating-point or if the vector attribute has no dimension vocabulary / names.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.