You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# score.py 1.0 generated by ADS 2.8.3-test-custom-scorepy on 20230331_192511
2
+
# THIS IS A CUSTOM SCORE.PY
3
+
importjson
4
+
importos
5
+
importcloudpickle
6
+
importpandasaspd
7
+
importnumpyasnp
8
+
fromfunctoolsimportlru_cache
9
+
10
+
11
+
model_name='model.pkl'
12
+
13
+
14
+
"""
15
+
Inference script. This script is used for prediction by scoring server when schema is known.
16
+
"""
17
+
18
+
19
+
@lru_cache(maxsize=10)
20
+
defload_model(model_file_name=model_name):
21
+
"""
22
+
Loads model from the serialized format
23
+
24
+
Returns
25
+
-------
26
+
model: a model instance on which predict API can be invoked
27
+
"""
28
+
returnmodel_file_name
29
+
30
+
defpre_inference(data):
31
+
"""
32
+
Preprocess data
33
+
34
+
Parameters
35
+
----------
36
+
data: Data format as expected by the predict API of the core estimator.
37
+
38
+
Returns
39
+
-------
40
+
data: Data format after any processing.
41
+
42
+
"""
43
+
returndata
44
+
45
+
46
+
defpost_inference(yhat):
47
+
"""
48
+
Post-process the model results
49
+
50
+
Parameters
51
+
----------
52
+
yhat: Data format after calling model.predict.
53
+
54
+
Returns
55
+
-------
56
+
yhat: Data format after any processing.
57
+
58
+
"""
59
+
returnyhat
60
+
61
+
defpredict(data, model=load_model()):
62
+
"""
63
+
Returns prediction given the model and data to predict
64
+
65
+
Parameters
66
+
----------
67
+
model: Model instance returned by load_model API
68
+
data: Data format as expected by the predict API of the core estimator. For eg. in case of sckit models it could be numpy array/List of list/Pandas DataFrame
69
+
70
+
Returns
71
+
-------
72
+
predictions: Output from scoring server
73
+
Format: {'prediction': output from model.predict method}
74
+
75
+
"""
76
+
return {'prediction': "This is a custom score.py."}
0 commit comments