{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "QUESTION:\n",
    "\n",
    "Doc1:(book, book, music, video, video)\n",
    "\n",
    "Doc2:(music, music, video)\n",
    "\n",
    "Doc3:(book, book, video)\n",
    "\n",
    "Use boolean representation; calculate cosine similarity between the documents. Use word frequency representation; calculate again. You can manually calculate them, or revise the sample code to do the calculation in Python.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9486832980505138\n"
     ]
    }
   ],
   "source": [
    "from numpy import dot\n",
    "from numpy.linalg import norm\n",
    "X = [1,2]\n",
    "Y = [2,2]\n",
    "cos_sim = dot(X,Y) / (norm(X)*norm(Y))\n",
    "print(cos_sim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5962847939999439\n"
     ]
    }
   ],
   "source": [
    "from numpy import dot\n",
    "from numpy.linalg import norm\n",
    "\n",
    "# BOOK is dimension 1\n",
    "# MUSIC is dimension 2\n",
    "# VIDEO is dimension 3\n",
    "\n",
    "# Not sure why erroring?\n",
    "# D1 = [2,1,2]\n",
    "# D2 = [0,2,1]\n",
    "# D3 = [2,0,1]\n",
    "# cos_sim = dot(D1,D2,D3) / (norm(D1)*norm(D2)*norm(D3))\n",
    "# print(cos_sim)\n",
    "\n",
    "# This works though \n",
    "D1 = [2,1,2]\n",
    "D2 = [0,2,1]\n",
    "# D3 = [2,0,1]\n",
    "cos_sim = dot(D1,D2) / (norm(D1)*norm(D2))\n",
    "print(cos_sim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
