Skip to content

Commit 7d14607

Browse files
committed
Update H2O logic for score code since H2O doesn't handle Path objects. Update the example files as well.
1 parent fb13cec commit 7d14607

File tree

9 files changed

+24
-16
lines changed

9 files changed

+24
-16
lines changed
459 Bytes
Binary file not shown.
Binary file not shown.

examples/data/hmeqModels/H2OBinaryGLM/inputVar.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
"name": "REASON",
2222
"level": "nominal",
2323
"type": "string",
24-
"length": 7.0
24+
"length": 7
2525
},
2626
{
2727
"name": "JOB",
2828
"level": "nominal",
2929
"type": "string",
30-
"length": 7.0
30+
"length": 7
3131
},
3232
{
3333
"name": "YOJ",

examples/data/hmeqModels/H2OBinaryGLM/score_glmfit_binary.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313

1414
h2o.init()
1515

16-
model = h2o.load(Path(settings.pickle_path))
16+
model = h2o.load(str(Path(settings.pickle_path) / glmfit.pickle))
1717

1818
def score(LOAN, MORTDUE, VALUE, REASON, JOB, YOJ, DEROG, DELINQ, CLAGE, NINQ, CLNO, DEBTINC):
1919
"Output: EM_CLASSIFICATION, EM_EVENTPROBABILITY"
2020

2121
try:
2222
global model
2323
except NameError:
24-
model = h2o.load(Path(settings.pickle_path))
24+
model = h2o.load(str(Path(settings.pickle_path) / glmfit.pickle))
25+
26+
2527

2628
try:
2729
if math.isnan(LOAN):
@@ -86,11 +88,11 @@ def score(LOAN, MORTDUE, VALUE, REASON, JOB, YOJ, DEROG, DELINQ, CLAGE, NINQ, CL
8688
columns=["LOAN", "MORTDUE", "VALUE", "REASON", "JOB", "YOJ", "DEROG", "DELINQ", "CLAGE", "NINQ", "CLNO", "DEBTINC"],
8789
dtype=float,
8890
index=[0])
89-
column_types = {['"LOAN" : "numeric"', '"MORTDUE" : "numeric"', '"VALUE" : "numeric"', '"REASON" : "string"', '"JOB" : "string"', '"YOJ" : "numeric"', '"DEROG" : "numeric"', '"DELINQ" : "numeric"', '"CLAGE" : "numeric"', '"NINQ" : "numeric"', '"CLNO" : "numeric"', '"DEBTINC" : "numeric"']}
91+
column_types = ['"LOAN" : "numeric"', '"MORTDUE" : "numeric"', '"VALUE" : "numeric"', '"REASON" : "string"', '"JOB" : "string"', '"YOJ" : "numeric"', '"DEROG" : "numeric"', '"DELINQ" : "numeric"', '"CLAGE" : "numeric"', '"NINQ" : "numeric"', '"CLNO" : "numeric"', '"DEBTINC" : "numeric"']
9092
h2o_array = h2o.H2OFrame(input_array, column_types=column_types)
9193
prediction = model.predict(h2o_array)
9294
prediction = h2o.as_list(prediction, use_pandas=False)
9395
EM_CLASSIFICATION = prediction[1][0]
94-
EM_EVENTPROBABILITY = prediction[1][1]
96+
EM_EVENTPROBABILITY = float(prediction[1][1])
9597

9698
return EM_CLASSIFICATION, EM_EVENTPROBABILITY
-21 Bytes
Binary file not shown.
Binary file not shown.

examples/data/hmeqModels/H2OMOJOGLM/inputVar.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
"name": "REASON",
2222
"level": "nominal",
2323
"type": "string",
24-
"length": 7.0
24+
"length": 7
2525
},
2626
{
2727
"name": "JOB",
2828
"level": "nominal",
2929
"type": "string",
30-
"length": 7.0
30+
"length": 7
3131
},
3232
{
3333
"name": "YOJ",

examples/data/hmeqModels/H2OMOJOGLM/score_glmfit_mojo.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313

1414
h2o.init()
1515

16-
model = h2o.import_mojo(Path(settings.pickle_path))
16+
model = h2o.import_mojo(str(Path(settings.pickle_path) / glmfit.mojo))
1717

1818
def score(LOAN, MORTDUE, VALUE, REASON, JOB, YOJ, DEROG, DELINQ, CLAGE, NINQ, CLNO, DEBTINC):
1919
"Output: EM_CLASSIFICATION, EM_EVENTPROBABILITY"
2020

2121
try:
2222
global model
2323
except NameError:
24-
model = h2o.import_mojo(Path(settings.pickle_path))
24+
model = h2o.import_mojo(str(Path(settings.pickle_path) / glmfit.mojo))
25+
26+
2527

2628
try:
2729
if math.isnan(LOAN):
@@ -86,11 +88,11 @@ def score(LOAN, MORTDUE, VALUE, REASON, JOB, YOJ, DEROG, DELINQ, CLAGE, NINQ, CL
8688
columns=["LOAN", "MORTDUE", "VALUE", "REASON", "JOB", "YOJ", "DEROG", "DELINQ", "CLAGE", "NINQ", "CLNO", "DEBTINC"],
8789
dtype=float,
8890
index=[0])
89-
column_types = {['"LOAN" : "numeric"', '"MORTDUE" : "numeric"', '"VALUE" : "numeric"', '"REASON" : "string"', '"JOB" : "string"', '"YOJ" : "numeric"', '"DEROG" : "numeric"', '"DELINQ" : "numeric"', '"CLAGE" : "numeric"', '"NINQ" : "numeric"', '"CLNO" : "numeric"', '"DEBTINC" : "numeric"']}
91+
column_types = ['"LOAN" : "numeric"', '"MORTDUE" : "numeric"', '"VALUE" : "numeric"', '"REASON" : "string"', '"JOB" : "string"', '"YOJ" : "numeric"', '"DEROG" : "numeric"', '"DELINQ" : "numeric"', '"CLAGE" : "numeric"', '"NINQ" : "numeric"', '"CLNO" : "numeric"', '"DEBTINC" : "numeric"']
9092
h2o_array = h2o.H2OFrame(input_array, column_types=column_types)
9193
prediction = model.predict(h2o_array)
9294
prediction = h2o.as_list(prediction, use_pandas=False)
9395
EM_CLASSIFICATION = prediction[1][0]
94-
EM_EVENTPROBABILITY = prediction[1][1]
96+
EM_EVENTPROBABILITY = float(prediction[1][1])
9597

9698
return EM_CLASSIFICATION, EM_EVENTPROBABILITY

src/sasctl/pzmm/write_score_code.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,15 @@ def _viya4_model_load(
507507
pickle_type = pickle_type if pickle_type else "pickle"
508508

509509
if mojo_model:
510-
cls.score_code += "model = h2o.import_mojo(Path(settings.pickle_path))\n\n"
511-
return f"{'':8}model = h2o.import_mojo(Path(settings.pickle_path))\n\n"
510+
cls.score_code += f"model = h2o.import_mojo(str(Path(settings.pickle_path" \
511+
f") / {model_file_name}))\n\n"
512+
return f"{'':8}model = h2o.import_mojo(str(Path(settings.pickle_path) / " \
513+
f"{model_file_name}))\n\n"
512514
elif binary_h2o_model:
513-
cls.score_code += "model = h2o.load(Path(settings.pickle_path))\n\n"
514-
return f"{'':8}model = h2o.load(Path(settings.pickle_path))\n\n"
515+
cls.score_code += f"model = h2o.load(str(Path(settings.pickle_path) / " \
516+
f"{model_file_name}))\n\n"
517+
return f"{'':8}model = h2o.load(str(Path(settings.pickle_path) / " \
518+
f"{model_file_name}))\n\n"
515519
else:
516520
cls.score_code += (
517521
f"with open(Path(settings.pickle_path) / "

0 commit comments

Comments
 (0)