示例#1
0
    def eval(self, test_dataset: GowallaTopNDataset):
        users = []
        ground_truth = []

        for user in test_dataset.get_all_users():
            user_positive_items = test_dataset.get_user_positives(user)
            if user_positive_items:
                users.append(user)
                ground_truth.append(user_positive_items)

        preds = self.recommend(users)
        max_length = max(map(len, metrics.metric_dict.keys())) + max(
            map(lambda x: len(str(x)), config['METRICS_REPORT']))
        for metric_name, metric_func in metrics.metric_dict.items():
            for k in config['METRICS_REPORT']:
                metric_name_total = f'{metric_name}@{k}'
                metric_value = metric_func(preds, ground_truth, k).mean()
                logger.info(f'{metric_name_total: >{max_length + 1}} = {metric_value}')
示例#2
0
from pathlib import Path
from config import config
from model import LightGCN, TopNModel, TopNPersonalized, TopNNearestModel
from dataloader import GowallaLightGCNDataset, GowallaTopNDataset, GowallaALSDataset

if __name__ == '__main__':
    dataset_path = Path('dataset') / config['DATASET'] / config['DATASET']
    if config['MODEL'] == 'LightGCN':
        train_dataset = GowallaLightGCNDataset(f'{dataset_path}_custom.train')
        test_dataset = GowallaLightGCNDataset(f'{dataset_path}_custom.test',
                                              train=False)

        model = LightGCN(train_dataset)
        model.fit(config['TRAIN_EPOCHS'], test_dataset)
    elif config['MODEL'] == 'TopNModel':
        train_dataset = GowallaTopNDataset(f'{dataset_path}.train')
        test_dataset = GowallaTopNDataset(f'{dataset_path}.test', train=False)

        model = TopNModel(config['TOP_N'])
        model.fit(train_dataset)
        model.eval(test_dataset)
    elif config['MODEL'] == 'TopNPersonalized':
        train_dataset = GowallaTopNDataset(f'{dataset_path}.train')
        test_dataset = GowallaTopNDataset(f'{dataset_path}.test', train=False)

        model = TopNPersonalized(config['TOP_N'])
        model.fit(train_dataset)
        model.eval(test_dataset)
    elif config['MODEL'] == 'TopNNearestModel':
        train_dataset = GowallaTopNDataset(f'{dataset_path}.train')
        test_dataset = GowallaTopNDataset(f'{dataset_path}.test', train=False)
示例#3
0
import pandas as pd
from config import config
from model import LightGCN, TopNModel, TopNPersonalized, TopNNearestModel
from dataloader import GowallaLightGCNDataset, GowallaTopNDataset, GowallaALSDataset

if __name__ == '__main__':
    dataset = config['DATASET']
    if config['MODEL'] == 'LightGCN':
        train_dataset = GowallaLightGCNDataset(f'dataset/{dataset}.train')
        test_dataset = GowallaLightGCNDataset(f'dataset/{dataset}.test',
                                              train=False)

        model = LightGCN(train_dataset)
        model.fit(config['TRAIN_EPOCHS'], test_dataset)
    elif config['MODEL'] == 'TopNModel':
        train_dataset = GowallaTopNDataset(f'dataset/{dataset}.train')
        test_dataset = GowallaTopNDataset(f'dataset/{dataset}.test',
                                          train=False)

        model = TopNModel(config['TOP_N'])
        model.fit(train_dataset)
        model.eval(test_dataset)
    elif config['MODEL'] == 'TopNPersonalized':
        train_dataset = GowallaTopNDataset(f'dataset/{dataset}.train')
        test_dataset = GowallaTopNDataset(f'dataset/{dataset}.test',
                                          train=False)

        model = TopNPersonalized(config['TOP_N'])
        model.fit(train_dataset)
        model.eval(test_dataset)
    elif config['MODEL'] == 'TopNNearestModel':