Skip to content

Commit

Permalink
prediction of ratings
Browse files Browse the repository at this point in the history
  • Loading branch information
uprestel committed May 31, 2020
1 parent 63f8ab4 commit e844e10
Showing 1 changed file with 147 additions and 4 deletions.
151 changes: 147 additions & 4 deletions project.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,7 @@
"colab": {}
},
"source": [
"#print(m,n)\n",
"#print(rec.shape)"
""
],
"execution_count": 0,
"outputs": []
Expand All @@ -894,7 +893,7 @@
"colab": {}
},
"source": [
"def training_validaton_split(B, omega,validation_size):\n",
"def training_validaton_split(B, omega, validation_size):\n",
" \"\"\"\n",
" splits the available data into a training and a validation set. Concretely this means that\n",
" we take randomly selected known ratings from the netflix matrix and put them into our validation set\n",
Expand Down Expand Up @@ -940,6 +939,150 @@
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "B62olo67Gdiz",
"colab_type": "text"
},
"source": [
"Now we can split up our known entires into a training and validation set and see how well the prediction aligns with the ground truth"
]
},
{
"cell_type": "code",
"metadata": {
"id": "NxjQzyILFhjl",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"outputId": "56b7b913-188e-432b-87c2-5b8758350df7"
},
"source": [
"B_train, validation_ratings, omega_train = training_validaton_split(B_dense, omega, validation_size=100)\n",
"A = construct_A(omega_train, m, n)\n",
"mask_train = (B_train!=0)\n",
"omegaval_train = np.where(mask_train!=0)\n",
"B = B_train[omegaval_train]\n",
"rec = DRS(A, B, m, n, iterations = 200, gamma = 1.9).reshape(m, n)\n",
"\n",
"# now we get the recommendations\n",
"for customer_id, movie_id, rating in validation_ratings:\n",
" predicted_rating = rec[customer_id, movie_id]\n",
" print(\"predicted: \", max(0, min(5, round(predicted_rating))), \"ground truth: \", rating)"
],
"execution_count": 114,
"outputs": [
{
"output_type": "stream",
"text": [
"predicted: 1.0 ground truth: 3\n",
"predicted: 5 ground truth: 3\n",
"predicted: 3.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 5\n",
"predicted: 2.0 ground truth: 1\n",
"predicted: 2.0 ground truth: 2\n",
"predicted: 2.0 ground truth: 4\n",
"predicted: 0 ground truth: 2\n",
"predicted: 2.0 ground truth: 4\n",
"predicted: 0 ground truth: 5\n",
"predicted: 3.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 4.0 ground truth: 5\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 0 ground truth: 4\n",
"predicted: 2.0 ground truth: 2\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 4\n",
"predicted: 3.0 ground truth: 2\n",
"predicted: 4.0 ground truth: 5\n",
"predicted: 0 ground truth: 1\n",
"predicted: 0 ground truth: 4\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 4.0 ground truth: 2\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 3.0 ground truth: 3\n",
"predicted: 1.0 ground truth: 2\n",
"predicted: 3.0 ground truth: 5\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 2.0 ground truth: 5\n",
"predicted: 2.0 ground truth: 2\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 0 ground truth: 4\n",
"predicted: 0 ground truth: 4\n",
"predicted: 5 ground truth: 5\n",
"predicted: 1.0 ground truth: 2\n",
"predicted: 3.0 ground truth: 3\n",
"predicted: 4.0 ground truth: 5\n",
"predicted: 0 ground truth: 2\n",
"predicted: 0 ground truth: 3\n",
"predicted: 4.0 ground truth: 4\n",
"predicted: 1.0 ground truth: 3\n",
"predicted: 0 ground truth: 1\n",
"predicted: 3.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 5\n",
"predicted: 4.0 ground truth: 5\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 1.0 ground truth: 3\n",
"predicted: 1.0 ground truth: 4\n",
"predicted: 4.0 ground truth: 3\n",
"predicted: 3.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 5\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 4.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 0 ground truth: 1\n",
"predicted: 1.0 ground truth: 2\n",
"predicted: 3.0 ground truth: 3\n",
"predicted: 3.0 ground truth: 2\n",
"predicted: 1.0 ground truth: 4\n",
"predicted: 3.0 ground truth: 5\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 4\n",
"predicted: 1.0 ground truth: 3\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 1.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 2.0 ground truth: 4\n",
"predicted: 4.0 ground truth: 3\n",
"predicted: 0 ground truth: 4\n",
"predicted: 0 ground truth: 1\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 2.0 ground truth: 2\n",
"predicted: 2.0 ground truth: 4\n",
"predicted: 1.0 ground truth: 2\n",
"predicted: 0 ground truth: 4\n",
"predicted: 3.0 ground truth: 3\n",
"predicted: 1.0 ground truth: 1\n",
"predicted: 0 ground truth: 2\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 1.0 ground truth: 3\n",
"predicted: 0 ground truth: 4\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 0 ground truth: 5\n",
"predicted: 2.0 ground truth: 3\n",
"predicted: 2.0 ground truth: 5\n",
"predicted: 1.0 ground truth: 5\n",
"predicted: 3.0 ground truth: 3\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 4.0 ground truth: 5\n",
"predicted: 1.0 ground truth: 4\n",
"predicted: 1.0 ground truth: 4\n",
"predicted: 3.0 ground truth: 4\n",
"predicted: 4.0 ground truth: 2\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -1050,7 +1193,7 @@
"colab": {}
},
"source": [
"def get_recommendation()"
""
],
"execution_count": 0,
"outputs": []
Expand Down

0 comments on commit e844e10

Please sign in to comment.