# Copyright 2018 The Cornac Authors. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
from ..recommender import Recommender
from ...exception import ScoreException
"""Global Average baseline for rating prediction. Rating predictions equal to average rating
of training data (not personalized).
name: string, default: 'GlobalAvg'
The name of the recommender model.
def __init__(self, name="GlobalAvg"):
[docs] def score(self, user_idx, item_idx=None):
"""Predict the scores/ratings of a user for an item.
user_idx: int, required
The index of the user for whom to perform score prediction.
item_idx: int, optional, default: None
The index of the item for which to perform score prediction.
If None, scores for all known items will be returned.
res : A scalar or a Numpy array
Relative scores that the user gives to the item or to all known items
if item_idx is None:
return np.full(self.train_set.num_items, self.train_set.global_mean)