<commit_before>#!/usr/bin/env python
"""
A module that provides functionalities for calculating error metrics
and evaluates the given recommender.
"""
import numpy
from sklearn.metrics import mean_squared_error
from util.top_recommendations import TopRecommendations


class Evaluator(object):
    """
    A class for computing evaluation metrics and splitting the input data.
    """
    def __init__(self, ratings, abstracts_preprocessor=None, random_seed=False):
        """
        Initialize an evaluator array with the initial actual ratings matrix.

        :param int[][] ratings: A numpy array containing the initial ratings.
        :param AbstractsPreprocessor abstracts_preprocessor: A list of the abstracts.
        :param bool random_seed: if False, we will use a fixed seed.
        """
        self.ratings = ratings
        if abstracts_preprocessor:
            self.abstracts_preprocessor = abstracts_preprocessor
        self.random_seed = random_seed
        self.k_folds = None

        # stores recommended indices for each user.
        self.recommendation_indices = [[] for i in range(self.ratings.shape[0])]
        # False if recommendations have not been loaded yet and vice versa.
        self.recs_loaded = False

        self.fold_train_indices = None
        self.fold_test_indices = None

    def get_abstracts_preprocessor(self):
        """
        Getter for the Abstracts preprocessor.

        :returns: abstracts preprocessor
        :rtype: AbstractsPreprocessor
        """
        return self.abstracts_preprocessor

    def get_ratings(self):<commit_msg>Fixed a small bug in item splitting<commit_after>#!/usr/bin/env python
"""
A module that provides functionalities for calculating error metrics
and evaluates the given recommender.
"""
import numpy
from sklearn.metrics import mean_squared_error
from util.top_recommendations import TopRecommendations


class Evaluator(object):
    """
    A class for computing evaluation metrics and splitting the input data.
    """
    def __init__(self, ratings, abstracts_preprocessor=None, random_seed=False):
        """
        Initialize an evaluator array with the initial actual ratings matrix.

        :param int[][] ratings: A numpy array containing the initial ratings.
        :param AbstractsPreprocessor abstracts_preprocessor: A list of the abstracts.
        :param bool random_seed: if False, we will use a fixed seed.
        """
        self.ratings = ratings
        self.n_users, self.n_items = ratings.shape
        if abstracts_preprocessor:
            self.abstracts_preprocessor = abstracts_preprocessor
        self.random_seed = random_seed
        self.k_folds = None

        # stores recommended indices for each user.
        self.recommendation_indices = [[] for i in range(self.ratings.shape[0])]
        # False if recommendations have not been loaded yet and vice versa.
        self.recs_loaded = False

        self.fold_train_indices = None
        self.fold_test_indices = None

    def get_abstracts_preprocessor(self):
        """
        Getter for the Abstracts preprocessor.

        :returns: abstracts preprocessor
        :rtype: AbstractsPreprocessor
        """
        return self.abstracts_preprocessor

    def get_ratings(self):
{'fraction_non_alphanumeric': 0.06580961126415671, 'fraction_numerical': 0.0006121824303642485, 'mean_word_length': 2.975669099756691, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4898167', 'n_tokens_mistral': 864, 'n_tokens_neox': 833, 'n_words': 282}