Response functions
Response functions are used to model users behaviour on items to simulate any kind of reaction that user perform. For example it can be binary classification model that determines whether user clicked on a item, or rating, that user gave to an item.
Base classes
All of the existing response functions are made on a top of underlying base classes
ActionModelEstimator
and ActionModelTransformer
which follows the logic of
spark’s Estimator and Transformer classes. To implement custom response function
the one can inherit from base classes:
ActionModelEstimator
if any learning logic is necessaryActionModelTransformer
for performing model infering
Base classes are inherited from spark’s Estimator and Transformer and to define fit()
or transform() logic the one should overwrite _fit()
and _transform()
respectively.
Note, that those base classes are useful to implement your own response function, but are not
necessary, and to create a response pipeline any proper spark’s estimators/transformers can be used
- class sim4rec.response.ActionModelEstimator(outputCol: str = None)
Base class for response estimator
- Parameters:
outputCol – Name of the response score column, defaults to None
- class sim4rec.response.ActionModelTransformer(outputCol: str = None)
Base class for response transformer. transform() will be used to calculate score based on inputCols, and write it to outputCol column
- Parameters:
outputCol – Name of the response score column, defaults to None
Response functions
- class sim4rec.response.ConstantResponse(value: float = 0.0, outputCol: str | None = None)
Always returns constant valued response
- Parameters:
value – Response value
outputCol – Output column name
- class sim4rec.response.NoiseResponse(mu: float | None = None, sigma: float | None = None, outputCol: str | None = None, clipNegative: bool = True, seed: int | None = None)
Creates random response sampled from normal distribution
- Parameters:
mu – Mean parameter of normal distribution
sigma – Standard deviation parameter of normal distribution
outputCol – Output column name
clip_negative – Whether to make response non-negative, defaults to True
seed – Random state seed, defaults to None
- class sim4rec.response.CosineSimilatiry(inputCols: List[str] | None = None, outputCol: str | None = None)
Calculates the cosine similarity between two vectors. The result is in [0; 1] range
- Parameters:
inputCols – Two column names with dense vectors
outputCol – Output column name
- class sim4rec.response.BernoulliResponse(inputCol: str | None = None, outputCol: str | None = None, seed: int | None = None)
Samples responses from probability column
- Parameters:
inputCol – Probability column name. Probability should be in range [0; 1]
outputCol – Output column name
seed – Random state seed, defaults to None
- class sim4rec.response.ParametricResponseFunction(inputCols: List[str] | None = None, outputCol: str | None = None, weights: Iterable | None = None)
Calculates response based on the weighted sum of input responses
- Parameters:
inputCols – Input responses column names
outputCol – Output column name
weights – Input responses weights