-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_model.py
More file actions
43 lines (33 loc) · 1.2 KB
/
test_model.py
File metadata and controls
43 lines (33 loc) · 1.2 KB
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
#fastscore.schema.0: input_schema.avsc
#fastscore.schema.1: output_schema.avsc
import json
import math
print("Starting program", flush=True)
# This is another test comment to see if it syncs.
# Removed a line and then added a line while using Unix formatting.
# Added this like while using Dos formatting. Does it sync to MOC?
#modelop.init
def begin():
global coefs
coefs = json.load(open('external_file_asset.json', 'r'))
print("pass", flush=True)
pass
#modelop.score
def action(datum):
prediction = compute_prediction(datum)
print("Can you hear me now?", flush=True)
yield prediction
def compute_prediction(datum):
x_score = coefs['x']*datum['x']
y_score = coefs['y']*datum['y']
prediction = x_score + y_score + coefs['intercept']
return prediction
#modelop.metrics
def metrics(data):
actuals = data.z.tolist()
data = data.to_dict(orient='records')
predictions = list(map(compute_prediction, data))
diffs = [x[0] - x[1] for x in zip(actuals, predictions)]
rmse = math.sqrt(sum(list(map(lambda x: x**2, diffs)))/len(diffs))
mae = sum(list(map(abs, diffs)))/len(diffs)
yield dict(MAE=mae, RMSE=rmse)