From ef2418036a6cfb25df818c45ae54802370d1027b Mon Sep 17 00:00:00 2001 From: Susan Li Date: Fri, 31 Dec 2021 00:05:45 -0500 Subject: [PATCH] Add notebook --- mainbpr.ipynb | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 mainbpr.ipynb diff --git a/mainbpr.ipynb b/mainbpr.ipynb new file mode 100644 index 0000000..ac7ecaf --- /dev/null +++ b/mainbpr.ipynb @@ -0,0 +1,88 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "4f81dbcc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Reading files...\n", + "Finished Reading files.\n", + "Iteration 0\n", + "Iteration 1\n", + "Iteration 2\n", + "Iteration 3\n", + "Iteration 4\n", + "Iteration 5\n", + "Iteration 6\n", + "Iteration 7\n", + "Iteration 8\n", + "Iteration 9\n", + "Finished updating.\n", + "Calculating Hit Rate...\n", + "Trained:\n", + "HitRate 0.5073891625615764\n", + "Number of Users:609\n", + "Number of Movies:9742\n" + ] + } + ], + "source": [ + "from filereader import read_ratings, read_movies\n", + "from bpr import bpr_update\n", + "from hitrate import hit_rate\n", + "from random import seed\n", + "from util import cov_matrix\n", + "from util import random_vector\n", + "import numpy as np\n", + "import random as random\n", + "seed(42)\n", + "np.random.seed(42)\n", + "print(\"Reading files...\")\n", + "users = read_ratings(\"data/ratings.csv\")\n", + "movies = read_movies(\"data/movies.csv\")\n", + "print(\"Finished Reading files.\")\n", + "iterations = 10\n", + "\n", + "for i in range(iterations):\n", + " print(\"Iteration \" + str(i))\n", + " bpr_update(users, movies)\n", + "\n", + "print(\"Finished updating.\")\n", + "print(\"Calculating Hit Rate...\")\n", + "\n", + "hits, denom, rms, rmsall = hit_rate(users, movies)\n", + "\n", + "print(\"Trained:\")\n", + "print(\"HitRate\" + ' ' + str(hits/denom))\n", + "print(\"Number of Users:\" + str(len(users)))\n", + "print(\"Number of Movies:\" + str(len(movies)))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}