src.fairreckitlib.model.pipeline.prediction_pipeline
This module contains a model pipeline that predicts known item ratings.
Classes:
PredictionPipeline: can batch predictions from multiple models for a specific API.
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)
1"""This module contains a model pipeline that predicts known item ratings. 2 3Classes: 4 5 PredictionPipeline: can batch predictions from multiple models for a specific API. 6 7This program has been developed by students from the bachelor Computer Science at 8Utrecht University within the Software Project course. 9© Copyright Utrecht University (Department of Information and Computing Sciences) 10""" 11 12from typing import List 13 14import pandas as pd 15 16from ..algorithms.base_predictor import BasePredictor 17from .model_pipeline import ModelPipeline 18 19 20class PredictionPipeline(ModelPipeline): 21 """Prediction Pipeline that computes user/item rating predictions. 22 23 The (user,item) prediction will be computed and for each pair that is present in the test set. 24 """ 25 26 def load_test_set_users(self) -> None: 27 """Load the test set users that all models can use for testing. 28 29 Predictions are made for every user-item pair in the test set. 30 31 Raises: 32 FileNotFoundError: when the test set file is not found. 33 """ 34 self.test_set_users = self.load_test_set_dataframe('prediction test set') 35 36 def test_model_ratings( 37 self, 38 model: BasePredictor, 39 user_batch: List[int], 40 **kwargs) -> pd.DataFrame: 41 """Test the specified model for rating predictions. 42 43 Predict ratings for each user-item pair that is present in the test set. 44 45 Args: 46 model: the model that needs to be tested. 47 user_batch: the user batch to compute model ratings for. 48 49 Raises: 50 ArithmeticError: possibly raised by a predictor model on testing. 51 MemoryError: possibly raised by a predictor model on testing. 52 RuntimeError: possibly raised by a predictor model on testing. 53 54 Returns: 55 a dataframe containing the computed rating predictions. 56 """ 57 return model.predict_batch(user_batch)
21class PredictionPipeline(ModelPipeline): 22 """Prediction Pipeline that computes user/item rating predictions. 23 24 The (user,item) prediction will be computed and for each pair that is present in the test set. 25 """ 26 27 def load_test_set_users(self) -> None: 28 """Load the test set users that all models can use for testing. 29 30 Predictions are made for every user-item pair in the test set. 31 32 Raises: 33 FileNotFoundError: when the test set file is not found. 34 """ 35 self.test_set_users = self.load_test_set_dataframe('prediction test set') 36 37 def test_model_ratings( 38 self, 39 model: BasePredictor, 40 user_batch: List[int], 41 **kwargs) -> pd.DataFrame: 42 """Test the specified model for rating predictions. 43 44 Predict ratings for each user-item pair that is present in the test set. 45 46 Args: 47 model: the model that needs to be tested. 48 user_batch: the user batch to compute model ratings for. 49 50 Raises: 51 ArithmeticError: possibly raised by a predictor model on testing. 52 MemoryError: possibly raised by a predictor model on testing. 53 RuntimeError: possibly raised by a predictor model on testing. 54 55 Returns: 56 a dataframe containing the computed rating predictions. 57 """ 58 return model.predict_batch(user_batch)
Prediction Pipeline that computes user/item rating predictions.
The (user,item) prediction will be computed and for each pair that is present in the test set.
27 def load_test_set_users(self) -> None: 28 """Load the test set users that all models can use for testing. 29 30 Predictions are made for every user-item pair in the test set. 31 32 Raises: 33 FileNotFoundError: when the test set file is not found. 34 """ 35 self.test_set_users = self.load_test_set_dataframe('prediction test set')
Load the test set users that all models can use for testing.
Predictions are made for every user-item pair in the test set.
Raises: FileNotFoundError: when the test set file is not found.
37 def test_model_ratings( 38 self, 39 model: BasePredictor, 40 user_batch: List[int], 41 **kwargs) -> pd.DataFrame: 42 """Test the specified model for rating predictions. 43 44 Predict ratings for each user-item pair that is present in the test set. 45 46 Args: 47 model: the model that needs to be tested. 48 user_batch: the user batch to compute model ratings for. 49 50 Raises: 51 ArithmeticError: possibly raised by a predictor model on testing. 52 MemoryError: possibly raised by a predictor model on testing. 53 RuntimeError: possibly raised by a predictor model on testing. 54 55 Returns: 56 a dataframe containing the computed rating predictions. 57 """ 58 return model.predict_batch(user_batch)
Test the specified model for rating predictions.
Predict ratings for each user-item pair that is present in the test set.
Args: model: the model that needs to be tested. user_batch: the user batch to compute model ratings for.
Raises: ArithmeticError: possibly raised by a predictor model on testing. MemoryError: possibly raised by a predictor model on testing. RuntimeError: possibly raised by a predictor model on testing.
Returns: a dataframe containing the computed rating predictions.
Inherited Members
- src.fairreckitlib.model.pipeline.model_pipeline.ModelPipeline
- ModelPipeline
- run
- run_model
- begin_model
- create_model_output_dir
- get_model_output_dir
- end_model
- on_load_train_set_matrix
- load_train_set_matrix
- load_train_set_dataframe
- load_test_set_dataframe
- reconstruct_ratings
- test_model
- train_model
- train_and_test_model