{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Algorithm Tuning\n", "\n", "This notebook examines the algorithm tuning process." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from collections import OrderedDict\n", "import pickle" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import seaborn as sns\n", "import pandas as pd\n", "import skopt\n", "import matplotlib.pyplot as plt\n", "from skopt.plots import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def read_opt(ds, algo):\n", " return skopt.load(f'data/{ds}/tuning/{algo}.opt')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def opt_df(opt):\n", " ys = pd.Series(opt.func_vals)\n", " cols = OrderedDict()\n", " for i, dim in enumerate(opt.space):\n", " cols[f'p{i}'] = pd.Series([x[i] for x in opt.x_iters])\n", " cols['y'] = -ys\n", " if hasattr(opt, 'iter_time'):\n", " cols['time'] = pd.Series(opt.iter_time).reindex(ys.index)\n", " return pd.DataFrame(cols)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def improvement_threshold(opt_df, col='y'):\n", " ymax = opt_df[col].max()\n", " return ymax - ymax * 0.01" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## User-User CF\n", "\n", "How does the user-user CF tuning perform?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "az_uu_i = read_opt('AZ', 'user-user-imp')\n", "az_uu_e = read_opt('AZ', 'user-user')\n", "bx_uu_i = read_opt('BX-I', 'user-user')\n", "bx_uu_e = read_opt('BX-E', 'user-user')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "BX-E UU plots:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_convergence(bx_uu_e)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_objective(bx_uu_e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "BX-I UU:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_convergence(bx_uu_i)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_objective(bx_uu_i)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ALS" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bx_als_e = read_opt('BX-E', 'als')\n", "bx_als_i = read_opt('BX-I', 'wrls')\n", "az_als_e = read_opt('AZ', 'als')\n", "az_als_i = read_opt('AZ', 'wrls-imp')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_convergence(bx_als_e)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_convergence(bx_als_i)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_objective(bx_als_i)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_convergence(az_als_e)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_objective(az_als_e)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_convergence(az_als_i)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_objective(az_als_i)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Evaluation Performance" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bxe_df = opt_df(bx_als_e)\n", "bxi_df = opt_df(bx_als_i)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### BX-E" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bxe_df.info()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sns.scatterplot(x='p0', y='time', data=bxe_df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.axvline(improvement_threshold(bxe_df), 0, 1, color='grey')\n", "sns.scatterplot(x='y', y='time', data=bxe_df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sns.scatterplot(x='y', y='time', data=bxe_df)\n", "plt.vlines(bxe_df.y.max() - 0.005, 0, bxe_df.time.max())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### BX-I" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bxi_df.info()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sns.scatterplot(x='p0', y='time', data=bxi_df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.axvline(improvement_threshold(bxi_df), 0, 1, color='black')\n", "sns.scatterplot(x='y', y='time', data=bxi_df)" ] }, { "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 }