Skip to content

Commit

Permalink
Add notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
susanli2016 authored Dec 31, 2021
1 parent 1e39790 commit ef24180
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions mainbpr.ipynb
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ef24180

Please sign in to comment.