-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_model.py
More file actions
33 lines (28 loc) · 890 Bytes
/
test_model.py
File metadata and controls
33 lines (28 loc) · 890 Bytes
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
#fastscore.schema.0: input_schema.avsc
#fastscore.schema.1: output_schema.avsc
import json
import math
#modelop.init
def begin():
global coefs
coefs = json.load(open('external_file_asset.json', 'r'))
pass
#a change
#modelop.score
def action(datum):
prediction = compute_prediction(datum)
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)