lenskit.knn.slim#

Sparse LInear Methods for Recommendation [NK11].

Classes

SLIMConfig(*[, l1_reg, l2_reg, max_iters, ...])

Hyperparameters for SLIM/fsSLIM (SlimScorer).

SLIMScorer([config])

Item scorer using Sparse LInear Methods (SLIM).

class lenskit.knn.slim.SLIMConfig(*, l1_reg=1.0, l2_reg=1.0, max_iters=100, max_nbrs=None)#

Bases: BaseModel

Hyperparameters for SLIM/fsSLIM (SlimScorer).

Parameters:
l1_reg: Annotated[float, Gt(gt=0)]#

L₁ regularization strength for SLIM.

l2_reg: Annotated[float, Gt(gt=0)]#

L₂ regularization strength for SLIM.

max_iters: Annotated[int, Gt(gt=0)]#

Maximum coordinate descent iterations per column.

max_nbrs: Annotated[int, Gt(gt=0)] | None#

Maximum neighbors (features) for each item. Setting this to a positive integer enables fsSLIM (with item cosine selection).

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class lenskit.knn.slim.SLIMScorer(config=None, **kwargs)#

Bases: Component, Trainable

Item scorer using Sparse LInear Methods (SLIM). SLIM was described for recommendation by :cite:t`ningSLIMSparseLinear2011`. This scorer supports both SLIM and fsSLIM variants (by setting SLIMConfig.max_nbrs).

SLIM operates by learning an elastic-net regression for each item, predicting whether the user will interact with that item based on the other items they have interacted with.

This implementation closely follows the paper with some reference to libslim for computational details. It uses coodrinate descent with soft thresholding [FHT10] to estimate the SLIM weight matrix.

Note

The coordinate descent method of Friedman et al. [FHT10] operates on standardized predictor variables, with a hint that standardization can be inlined to the optimization logic for sparse problems. However, they do not provide details for how to do that inlining, and the original SLIM implementation from the Karypis lab does not appear to center the predictors. Therefore, this implementation also does not center them.

Parameters:
train(data, options)#

Train the model to learn its parameters from a training dataset.

Parameters: