{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import pandas as pd\n", "import numpy as np\n", "from sklearn.linear_model import LinearRegression\n", "import matplotlib.pyplot as plt\n", "import matplotlib" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "directory = '/results'\n", "#filename = 'exp1002_uc3_75000_1_totallag.csv'\n", "filename = 'exp1002_uc3_50000_2_totallag.csv'\n", "warmup_sec = 60\n", "threshold = 2000 #slope" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(os.path.join(directory, filename))\n", "\n", "input = df.iloc[::3]\n", "#print(input)\n", "input['sec_start'] = input.loc[0:, 'timestamp'] - input.iloc[0]['timestamp']\n", "#print(input)\n", "#print(input.iloc[0, 'timestamp'])\n", "regress = input.loc[input['sec_start'] >= warmup_sec] # Warm-Up\n", "#regress = input\n", "\n", "#input.plot(kind='line',x='timestamp',y='value',color='red')\n", "#plt.show()\n", "\n", "X = regress.iloc[:, 4].values.reshape(-1, 1) # values converts it into a numpy array\n", "Y = regress.iloc[:, 3].values.reshape(-1, 1) # -1 means that calculate the dimension of rows, but have 1 column\n", "linear_regressor = LinearRegression() # create object for the class\n", "linear_regressor.fit(X, Y) # perform linear regression\n", "Y_pred = linear_regressor.predict(X) # make predictions" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(linear_regressor.coef_)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.style.use('ggplot')\n", "plt.rcParams['axes.facecolor']='w'\n", "plt.rcParams['axes.edgecolor']='555555'\n", "#plt.rcParams['ytick.color']='black'\n", "plt.rcParams['grid.color']='dddddd'\n", "plt.rcParams['axes.spines.top']='false'\n", "plt.rcParams['axes.spines.right']='false'\n", "plt.rcParams['legend.frameon']='true'\n", "plt.rcParams['legend.framealpha']='1'\n", "plt.rcParams['legend.edgecolor']='1'\n", "plt.rcParams['legend.borderpad']='1'\n", "\n", "\n", "#filename = f\"exp{exp_id}_{benchmark}_{dim_value}_{instances}\"\n", "\n", "\n", "t_warmup = input.loc[input['sec_start'] <= warmup_sec].iloc[:, 4].values\n", "y_warmup = input.loc[input['sec_start'] <= warmup_sec].iloc[:, 3].values\n", "\n", "plt.figure()\n", "#plt.figure(figsize=(4, 3))\n", "\n", "plt.plot(X, Y, c=\"#348ABD\", label=\"observed\")\n", "#plt.plot(t_warmup, y_warmup)\n", "\n", "plt.plot(X, Y_pred, c=\"#E24A33\", label=\"trend\") # color='red')\n", "\n", "#348ABD, 7A68A6, A60628, 467821, CF4457, 188487, E24A33\n", "\n", "plt.gca().yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, pos: '%1.0fK' % (x * 1e-3)))\n", "plt.ylabel('queued messages')\n", "plt.xlabel('seconds since start')\n", "plt.legend()\n", "#ax.set_ylim(ymin=0)\n", "#ax.set_xlim(xmin=0)\n", "\n", "plt.savefig(\"plot.pdf\", bbox_inches='tight')\n" ] } ], "metadata": { "language_info": { "name": "python", "codemirror_mode": { "name": "ipython", "version": 3 }, "version": "3.7.0-final" }, "orig_nbformat": 2, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "npconvert_exporter": "python", "pygments_lexer": "ipython3", "version": 3, "kernelspec": { "name": "python37064bitvenvvenv21b61136d7f443749f2918b47e00d223", "display_name": "Python 3.7.0 64-bit ('.venv': venv)" } }, "nbformat": 4, "nbformat_minor": 2 }