meh/recommender-systems-class-master/jupyter_test.ipynb

225 lines
62 KiB
Plaintext
Raw Normal View History

2021-07-07 20:03:54 +02:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "spread-happiness",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"import numpy as np\n",
"import pandas as pd\n",
"import torch\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"from IPython.display import Markdown, display, HTML\n",
"\n",
"# Fix the dying kernel problem (only a problem in some installations - you can remove it, if it works without it)\n",
"import os\n",
"os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "adult-compensation",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Numpy array\n",
"[[1. 2. 3.]\n",
" [4. 5. 6.]\n",
" [7. 8. 9.]]\n",
"\n",
"Pandas DataFrame\n",
" A B C\n",
"0 1.0 2.0 3.0\n",
"1 4.0 5.0 6.0\n",
"2 7.0 8.0 9.0\n",
"\n",
"Pretty display of pandas DataFrame\n"
]
},
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>A</th>\n",
" <th>B</th>\n",
" <th>C</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>3.0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4.0</td>\n",
" <td>5.0</td>\n",
" <td>6.0</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7.0</td>\n",
" <td>8.0</td>\n",
" <td>9.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"PyTorch tensor\n",
"tensor([[1., 2., 3.],\n",
" [4., 5., 6.],\n",
" [7., 8., 9.]], dtype=torch.float64)\n",
"\n",
"Matplolib chart\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAhNElEQVR4nO3deWAU9d3H8fcPCOQAwpFwhhBuyAGI4VaLiBUVRcCz9UTFtmprn1aIKAiCFahaaWtVtIpWq48lQRARUcSjXggeOTlCuEICCQRy3/t7/ki0lEdFsptMdvfz+iebyWbnM4Z8nMzOfMdYaxEREe/TwukAIiLSMCpwEREvpQIXEfFSKnARES+lAhcR8VKtmnJlYWFhNioqqilXKSLi9bZt23bEWht+8vImLfCoqCi2bt3alKsUEfF6xph937Vch1BERLyUClxExEupwEVEvFSTHgP/LtXV1WRnZ1NRUeF0lCYXGBhIREQEAQEBTkcRES/keIFnZ2fTrl07oqKiMMY4HafJWGs5evQo2dnZ9OnTx+k4IuKFTnkIxRjzrDEmzxiTesKyTsaYt40xu+o/dmxogIqKCjp37uxX5Q1gjKFz585++ZeHiHjGjzkGvhKYfNKyBGCTtXYAsKn+8wbzt/L+hr9ut4h4xikL3Fr7AVBw0uKpwPP1j58HLvNsLBER33DweDkLX0+jptbl8ddu6FkoXa21ufWPDwFdv++JxphZxpitxpit+fn5DVxd42rbti0AOTk5XH755Q6nERFf4HJZ/vHJXn766Pu8suUA6blFHl+H229iWmutMeZ77wphrV0BrACIj49v1neP6NGjB6tWrWrUddTU1NCqlePvHYtII8rKLyEhMYUtews4e0AYf5gWR69OwR5fT0P3wA8bY7oD1H/M81wk5+zdu5fY2FgAVq5cyfTp05k8eTIDBgxg9uzZ3z5v48aNjB07lhEjRnDFFVdQUlICwAMPPMDIkSOJjY1l1qxZfHO3owkTJnDXXXcRHx/P8uXL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txpOfZ4yZBcwCiIyMbOjqRMSL7ThUzOxVX/N1diGThnRh8WVxdAsNdDqW12vw27zGmI7AVKAP0AMIMcZce/LzrLUrrLXx1tr48PDwhicVEa9TWVPLn97eyZS/fMiBY+X8+ZozePr6eJW3h7hzCGUSsMdamw9gjEkCxgEveiKYiHi3L/cfY05iMjsPl3DZ8B7MvySGTiGtnY7lU9wp8P3AGGNMMHWHUM4DtnoklYh4rfKqWh7ZuIO/f7SHbu0DefbGeCYO1vCpxuDOMfDPjDGrgC+AGuBLYIWngomI9/l49xESElPYX1DGz0ZHcs+Fg2mn4VONxq2zUKy19wP3eyiLiHipoopqHlqfwctbDhDVOZhXZo1hTN/OTsfyeboSU0Tc8k76Ye59LYX84kpmndOX304aqOFTTUQFLiINcrSkkgWvp/P61zkM7taOp6+PZ2hEB6dj+RUVuIicFmsta77KYeHraZRU1vA/5w/kFz/pp+FTDlCBi8iPlnO8nPteS+Xd7XmcEdmBpTOGMrCrhk85RQUuIqfkcln+uWU/S97cTq3LMn9KNDeMi9LwKYepwEXkB+05UsqcxGS27CngrP5hPDQ9jl6dgp2OJajAReR71NS6eObfe/jT2ztp3aoFy2YM5Yr4CA2fakZU4CLy/2TkFjEnMZnk7EJ+Gt2VRZfF0rW95pc0NypwEflWZU0tj7+byd/e201oUACP/2wEF8V10153M6UCFxEAtu2rGz6VmVfC9DN6Mm9KNB01fKpZU4GL+Lmyqhr++NYOVn68lx6hQTx300jOHdTF6VjyI6jARfzYv3cdISEpmexj5Vw/tjezJw+mbRvVgrfQT0rEDxWWVfPg+nRe3ZpN37AQXr1tLKP6dHI6lpw
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Seaborn chart\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAtgAAAFqCAYAAAAgOS3mAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90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vKrX/1KLr74YslkMiIicv/998tZZ50lIiIf/vCH5R3veIcUCgUZHByU17zmNfIf//EfIiLy7//+7/Ke97xHRESuvfZa+dGPfiQiIoVCQc4991y54447RETkNa95jYyMjMx6PUQLwQo2rThHHXUUrrvuOlxyySU44YQT8O53vxv77rsvbrzxRgwODuKP//iPi+dVSuGll17CQQcdhOuuuw5/9Ed/hPPOOw9btmyZcbnzqWADwOmnnw4A2HvvvQEAJ598MgBgn332wUMPPQQAuPbaa/E///M/+Od//me88MILyOVyyGQy6O7uLl7OvffeiyeffLJ4Ha7rIpvNLmzjEBHNolVeP3333XcfduzYgYsuuqj4u4mJCYyPjwMATj31VITDYfT19SGRSJS9zvrnufLKK/HAAw/ghhtuwIsvvojBwUFkMpm6ryf4ekxULwZsWnH23ntv/OxnP8OvfvUr/PKXv8R73vMeXH311XBdF8cffzy+9KUvFc+7e/du9Pf3AwC2b9+O7u5uPP300ygUCohEImWXe8ABB+DWW2+texyVfx8Oh2ec513vehcOOuggnHzyyTjrrLPw+OOPQ0TKzuO6Li699FJcfPHFAIBCoYCJiYm6x0FEVK9Wef30ua6L888/H1deeWXx58HBQXR1dQGY+TobCs2MNX/9138Nx3Fw1lln4Y1vfCN2795d9XV2tushmi9OcqQV59vf/jauuuoqnHTSSbjyyitx0kkn4dlnn8Vxxx2HBx54AM8//zwA4L//+79x3nnnIZ/PY+fOnbjmmmvwr//6r9h///3xxS9+senjnJiYwP/+7//ib/7mb/DmN78ZAwMDeOmll+C6btn5TjrpJHz/+9/H9PQ0AOD666/Hhz70oaaPj4hWn1Z7/TzxxBNx++23Y3BwEADwne98B+9+97vndRm/+MUv8P73vx9nn302lFJ4/PHH4ThOw6+HKIgVbFpx3vKWt+Chhx7C2WefjXg8jr322gtbt25FV1cXPvnJT+Kv//qvISIIhUL46le/ikgkgg9+8IN43/veh9e85jX4u7/7O2zZsgUnnHAC3vjGNzZtnF1dXfiTP/kTvPWtb0V3dzd6enrwute9Djt27Ci2lQDAO97xDgwMD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qj2BoaKrs+pHP67+xLf1dKSAShUQiUPm83m7+ZfrXV7whCrK2X/87k4ayLCAahXR2QRJJGDu216x4B+875PP6sl0HynUhUIBjl26jYQCGAenoLAZud69NMJ/5LcQwq96Xasd2hO65U1+/65a2jRkCxNWPg3AU6OmBff475n1fDz/yRDEIzvZYmu2+DobJeh6Pasd2hO69U28v/z6PRmGfesaM8zfq8dhM1cYYuvVmIJ0GwoH3OcsCksl530+NsFJfU1vv3WseHn5B4DhAOg84LmAaQCwE3P+MYPMGfZ67n7Jw79OAAmAowHL1V9gEIiGFSAiALWV/M5v7nxGEDP23AOb992WBJ4JlqdYFb4NSSt+WOm5DZZDbr0+wfUhhLC1wBZjM6m1sKMCygXufBgCrGLKDf5+1gIgJJCKl7VjICb73KxfxsDsjKC5ku1du693jghesmeezvceDUgBcYM8E8IXbrXlV1ZerOjzX42mh9/VSGksL4pHy34VN/XtaWuqVl2EGK1tjYzB37YQkkpB4YvbKqx8KHRtwbKhQCBIOA+EwxALMxx6BXSNQNDp8VK3Q/eyngOMArlMaq+k9V5UCXBfm47+Be8zxemfBD52A3vMGdOAKsu3S30PpoFnl+tXUZPnfiQD5HFQ+Vwy2cJz
"text/plain": [
"<Figure size 720x360 with 2 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"a = np.array(\n",
" [[1.0, 2.0, 3.0], \n",
" [4.0, 5.0, 6.0], \n",
" [7.0, 8.0, 9.0]]\n",
")\n",
"\n",
"print(\"Numpy array\")\n",
"print(a)\n",
"print()\n",
"\n",
"df = pd.DataFrame(a, columns=['A', 'B', 'C'])\n",
"\n",
"print(\"Pandas DataFrame\")\n",
"print(df)\n",
"print()\n",
"\n",
"print(\"Pretty display of pandas DataFrame\")\n",
"display(HTML(df.to_html(index=False)))\n",
"print()\n",
"\n",
"tensor = torch.from_numpy(a)\n",
"\n",
"print(\"PyTorch tensor\")\n",
"print(tensor)\n",
"print()\n",
"\n",
"# Matplotlib\n",
"\n",
"print(\"Matplolib chart\")\n",
"\n",
"# Prepare the data\n",
"x = np.linspace(0, 10, 100)\n",
"\n",
"# Plot the data\n",
"plt.plot(x, x, label='linear')\n",
"\n",
"# Add a legend\n",
"plt.legend()\n",
"\n",
"# Show the plot\n",
"plt.show()\n",
"\n",
"# Seaborn\n",
"\n",
"print(\"Seaborn chart\")\n",
"\n",
"sns.set_theme(style=\"darkgrid\")\n",
"\n",
"# Load the example Titanic dataset (the dataset may load some time)\n",
"df = sns.load_dataset(\"titanic\")\n",
"\n",
"# Make a custom palette with gendered colors\n",
"pal = dict(male=\"#6495ED\", female=\"#F08080\")\n",
"\n",
"# Show the survival probability as a function of age and sex\n",
"g = sns.lmplot(x=\"age\", y=\"survived\", col=\"sex\", hue=\"sex\", data=df,\n",
" palette=pal, y_jitter=.02, logistic=True, truncate=False)\n",
"g.set(xlim=(0, 80), ylim=(-.05, 1.05))\n",
"\n",
"# Show the plot\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "apparent-first",
"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.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}