-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathols.py
71 lines (53 loc) · 2.11 KB
/
ols.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pylint: disable=invalid-name
import sys
import statsmodels.formula.api as smf
import pandas as pd
def train_model(cpu_chips, ram, tdp, cpu_threads):
df = pd.read_csv('./data/spec_data_cleaned.csv')
formula = 'power ~ utilization'
if cpu_threads is not None:
formula = f"{formula} + CPUThreads"
if cpu_chips is not None:
formula = f"{formula}*C(CPUChips)"
if ram is not None:
formula = f"{formula} + HW_MemAmountGB"
if tdp is not None:
formula = f"{formula} + TDP"
return smf.ols(formula=formula, data=df).fit()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--cpu-chips', type=float, help='Number of CPUChips')
parser.add_argument('--cpu-threads', type=float, help='Number of CPU Threads')
parser.add_argument('--cpu-freq',
type=float,
help='CPU frequency. (Not used. Only for compatibility with XGBoost model)'
)
parser.add_argument('--tdp', type=float, help='TDP of the CPU')
parser.add_argument('--ram', type=float, help='Amount of RAM for the bare metal system')
parser.add_argument('--vhost-ratio',
type=float,
help='Virtualization ratio of the system. Input numbers between (0,1].',
default=1.0
)
parser.add_argument('--silent',
action='store_true',
help='Will suppress all debug output. Typically used in production.'
)
args = parser.parse_args()
model = train_model(args.cpu_chips, args.ram, args.tdp, args.cpu_threads)
my_data = pd.DataFrame.from_dict({
'utilization': 0,
'CPUChips': [args.cpu_chips],
'CPUThreads': [args.cpu_threads],
'HW_MemAmountGB': [args.ram],
'TDP' : [args.tdp]
})
# Drop all arguments that were not supplied
my_data = my_data.dropna(axis=1)
if not args.silent:
print('Sending following dataframe to model', my_data)
print('vHost ratio is set to ', args.vhost_ratio)
for line in sys.stdin:
my_data['utilization'] = float(line.strip())
print(model.predict(my_data)[0] * args.vhost_ratio)