Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
theodolite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sören Henning
theodolite
Commits
975b3c9b
Commit
975b3c9b
authored
4 years ago
by
Sören Henning
Browse files
Options
Downloads
Patches
Plain Diff
Add lag trend notebook
parent
aea1e4e6
No related branches found
No related tags found
No related merge requests found
Pipeline
#424
passed
4 years ago
Stage: build
Stage: test
Stage: check
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
execution/lag-trend-graph.ipynb
+147
-0
147 additions, 0 deletions
execution/lag-trend-graph.ipynb
with
147 additions
and
0 deletions
execution/lag-trend-graph.ipynb
0 → 100644
+
147
−
0
View file @
975b3c9b
{
"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 = ''\n",
"filename = 'xxx_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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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": "python37064bitvenvvenv469ea2e0a7854dc7b367eee45386afee",
"display_name": "Python 3.7.0 64-bit ('.venv': venv)"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
\ No newline at end of file
%% Cell type:code id: tags:
```
import os
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
import matplotlib
```
%% Cell type:code id: tags:
```
directory = ''
filename = 'xxx_totallag.csv'
warmup_sec = 60
threshold = 2000 #slope
```
%% Cell type:code id: tags:
```
df = pd.read_csv(os.path.join(directory, filename))
input = df.iloc[::3]
#print(input)
input['sec_start'] = input.loc[0:, 'timestamp'] - input.iloc[0]['timestamp']
#print(input)
#print(input.iloc[0, 'timestamp'])
regress = input.loc[input['sec_start'] >= warmup_sec] # Warm-Up
#regress = input
#input.plot(kind='line',x='timestamp',y='value',color='red')
#plt.show()
X = regress.iloc[:, 4].values.reshape(-1, 1) # values converts it into a numpy array
Y = regress.iloc[:, 3].values.reshape(-1, 1) # -1 means that calculate the dimension of rows, but have 1 column
linear_regressor = LinearRegression() # create object for the class
linear_regressor.fit(X, Y) # perform linear regression
Y_pred = linear_regressor.predict(X) # make predictions
```
%% Cell type:code id: tags:
```
print(linear_regressor.coef_)
```
%% Cell type:code id: tags:
```
plt.style.use('ggplot')
plt.rcParams['axes.facecolor']='w'
plt.rcParams['axes.edgecolor']='555555'
#plt.rcParams['ytick.color']='black'
plt.rcParams['grid.color']='dddddd'
plt.rcParams['axes.spines.top']='false'
plt.rcParams['axes.spines.right']='false'
plt.rcParams['legend.frameon']='true'
plt.rcParams['legend.framealpha']='1'
plt.rcParams['legend.edgecolor']='1'
plt.rcParams['legend.borderpad']='1'
#filename = f"exp{exp_id}_{benchmark}_{dim_value}_{instances}"
t_warmup = input.loc[input['sec_start'] <= warmup_sec].iloc[:, 4].values
y_warmup = input.loc[input['sec_start'] <= warmup_sec].iloc[:, 3].values
plt.figure()
#plt.figure(figsize=(4, 3))
plt.plot(X, Y, c="#348ABD", label="observed")
#plt.plot(t_warmup, y_warmup)
plt.plot(X, Y_pred, c="#E24A33", label="trend") # color='red')
#348ABD, 7A68A6, A60628, 467821, CF4457, 188487, E24A33
plt.gca().yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, pos: '%1.0fK' % (x * 1e-3)))
plt.ylabel('queued messages')
plt.xlabel('seconds since start')
plt.legend()
#ax.set_ylim(ymin=0)
#ax.set_xlim(xmin=0)
plt.savefig("plot.pdf", bbox_inches='tight')
```
%% Cell type:code id: tags:
```
```
%% Cell type:code id: tags:
```
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment