Passed
Push — master ( ccc735...5b9e9c )
by Simon
01:52
created

plot.plot_optimizer_time()   A

Complexity

Conditions 1

Size

Total Lines 47
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 47
rs 9.28
c 0
b 0
f 0
cc 1
nop 5
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
import numpy as np
7
import pandas as pd
8
import matplotlib.pyplot as plt
9
from matplotlib.ticker import MultipleLocator
10
11
# import matplotlib as mpl
12
import seaborn as sns
13
14
ml = MultipleLocator(5)
15
sns.set(style="whitegrid")
16
17
18
def plot_optimizer_time(model_name, y_min, y_max, step_major, title):
19
    file_name = "optimizer_calc_time_" + model_name
20
21
    data = pd.read_csv("./data/" + file_name, header=0)
22
23
    columns = data.columns
24
    values = data.values
25
26
    no_opt = values[:, 0]
27
28
    values_norm = values / no_opt[:, None]
29
30
    fig, ax = plt.subplots()
31
    plt.figure(figsize=(10, 8))
32
    # plt.grid(True)
33
    # plt.ylabel(r"$\dfrac{T_{norm}}{iteration}$", rotation=0)
34
    plt.ylabel(r"$T_{norm}$", rotation=0)
35
36
    data = pd.DataFrame(values_norm, columns=columns)
37
    ax = sns.barplot(data=data, alpha=0.75, capsize=0.1)
38
    # ax = sns.barplot(x=columns, y=values_norm, alpha=0.75, ci="sd")
39
    ax.set_xticklabels(ax.get_xticklabels(), rotation=75)
40
    ax.set_title(title)
41
42
    # ax.tick_params(axis="x", which="minor", bottom=False)
43
    # ax.yaxis.set_minor_locator(ml)
44
45
    # ax.set_yscale("log")
46
    y_min = y_min
47
    y_max = y_max
48
    step_major = step_major
49
    # step_minor = 0.025
50
51
    ax.set_ylim(y_min, y_max)
52
    ticks_major = list(np.arange(y_min, y_max, step_major))
53
    # ticks_minor = list(np.arange(y_min, y_max, step_minor))
54
55
    ax.yaxis.set_ticks(ticks_major)
56
    # ax.yaxis.set_ticks(ticks_minor, minor=True)
57
58
    ax.xaxis.set_label_coords(-0.05, 0.5)
59
    ax.get_yaxis().set_label_coords(-0.05, 1.1)
60
61
    # ax.yaxis.grid(which="minor", color="r", linestyle="-", linewidth=2)
62
    fig = ax.get_figure()
63
    fig.tight_layout()
64
    fig.savefig("optimizer_time_" + model_name + ".png")
65
66
67
plot_optimizer_time(
68
    "sklearn.neighbors.KNeighborsClassifier",
69
    y_min=0.50,
70
    y_max=4.50001,
71
    step_major=0.50,
72
    title="KNeighborsClassifier - iris_data",
73
)
74
75
plot_optimizer_time(
76
    "sklearn.ensemble.GradientBoostingClassifier",
77
    y_min=0.50,
78
    y_max=1.50001,
79
    step_major=0.25,
80
    title="GradientBoostingClassifier - cancer_data",
81
)
82
83
plot_optimizer_time(
84
    "sklearn.tree.DecisionTreeClassifier",
85
    y_min=0.50,
86
    y_max=3.000001,
87
    step_major=0.50,
88
    title="DecisionTreeClassifier - iris_data",
89
)
90
91
plot_optimizer_time(
92
    "lightgbm.LGBMClassifier",
93
    y_min=0.50,
94
    y_max=1.500001,
95
    step_major=0.25,
96
    title="LGBMClassifier - cancer_data",
97
)
98