-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Random algorithm to GeneralRecommenders
feat: add Random algorithm to GeneralRecommenders
- Loading branch information
Showing
6 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Random | ||
=========== | ||
|
||
Introduction | ||
--------------------- | ||
|
||
When discussing recommendation systems, accuracy is often regarded as the most crucial metric. | ||
However, besides accuracy, several other key metrics can evaluate the effectiveness of a recommendation system, such as diversity, coverage, and efficiency. | ||
In this context, the random recommendation algorithm is a valuable baseline. | ||
In terms of implementation, for a given user and item, the random recommendation algorithm provides a random rating. | ||
|
||
Running with RecBole | ||
|
||
|
||
|
||
**A Running Example:** | ||
|
||
Write the following code to a python file, such as `run.py` | ||
|
||
.. code:: python | ||
from recbole.quick_start import run_recbole | ||
run_recbole(model='Random', dataset='ml-100k') | ||
And then: | ||
|
||
.. code:: bash | ||
python run.py | ||
If you want to change parameters, dataset or evaluation settings, take a look at | ||
|
||
- :doc:`../../../user_guide/config_settings` | ||
- :doc:`../../../user_guide/data_intro` | ||
- :doc:`../../../user_guide/train_eval_intro` | ||
- :doc:`../../../user_guide/usage` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2023/03/01 | ||
# @Author : João Felipe Guedes | ||
# @Email : [email protected] | ||
# UPDATE | ||
|
||
r""" | ||
Random | ||
################################################ | ||
""" | ||
|
||
import torch | ||
import random | ||
|
||
from recbole.model.abstract_recommender import GeneralRecommender | ||
from recbole.utils import InputType, ModelType | ||
|
||
|
||
class Random(GeneralRecommender): | ||
"""Random is an fundamental model that recommends random items.""" | ||
|
||
input_type = InputType.POINTWISE | ||
type = ModelType.TRADITIONAL | ||
|
||
def __init__(self, config, dataset): | ||
super(Random, self).__init__(config, dataset) | ||
torch.manual_seed(config["seed"] + self.n_users + self.n_items) | ||
self.fake_loss = torch.nn.Parameter(torch.zeros(1)) | ||
|
||
def forward(self): | ||
pass | ||
|
||
def calculate_loss(self, interaction): | ||
return torch.nn.Parameter(torch.zeros(1)) | ||
|
||
def predict(self, interaction): | ||
return torch.rand(len(interaction)).squeeze(-1) | ||
|
||
def full_sort_predict(self, interaction): | ||
batch_user_num = interaction[self.USER_ID].shape[0] | ||
result = torch.rand(self.n_items, 1).to(torch.float64) | ||
result = torch.repeat_interleave(result.unsqueeze(0), batch_user_num, dim=0) | ||
return result.view(-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters