Requesting Contributions
Requesting contributions when scoring.
Prerequisites
h2o_mlops_scoring_client-*-py3-none-any.whl
file or access to the Python Package Index (PyPI)- Java
Setup
Install the h2o_mlops_scoring_client
with pip
.
Notes
- If running locally, the number of cores used (and thus parallel processes) can be overridden with:
num_cores = 10
h2o_mlops_scoring_client.spark_master = f"local[{num_cores}]"
Example Usage for Data Frames
import h2o_mlops_scoring_client
import pandas
Choose a feature type for contributions - either original or transformed.
CONTRIB_FEATURE_TYPE = h2o_mlops_scoring_client.FeatureType.ORIGINAL
Pass the feature type when scoring.
ID_COLUMN = "ID"
MLOPS_ENDPOINT_URL = "https://model.internal.dedicated.h2o.ai/65427177-dd10-44dd-abf8-76ab29f60799/model/score"
DATA_FRAME = pandas.read_csv("/Users/jgranados/datasets/creditcard.csv")
h2o_mlops_scoring_client.score_data_frame(
mlops_endpoint_url=MLOPS_ENDPOINT_URL,
data_frame=DATA_FRAME,
id_column=ID_COLUMN,
request_contributions=CONTRIB_FEATURE_TYPE
)
23/08/24 16:08:28 INFO h2o_mlops_scoring_client: Connecting to H2O.ai MLOps scorer at 'https://model.internal.dedicated.h2o.ai/65427177-dd10-44dd-abf8-76ab29f60799/model/score'
23/08/24 16:08:28 INFO h2o_mlops_scoring_client: Starting scoring data frame
23/08/24 16:09:04 INFO h2o_mlops_scoring_client: Scoring complete
23/08/24 16:09:04 INFO h2o_mlops_scoring_client: Total run time: 0:00:36
23/08/24 16:09:04 INFO h2o_mlops_scoring_client: Scoring run time: 0:00:36
ID | default payment next month.0 | default payment next month.1 | contrib_LIMIT_BAL | contrib_MARRIAGE | contrib_AGE | contrib_PAt_0 | contrib_PAY_2 | contrib_PAY_3 | contrib_PAY_4 | ... | contrib_BILL_AMT4 | contrib_BILL_AMT5 | contrib_BILL_AMT6 | contrib_PAY_AMT1 | contrib_PAY_AMT2 | contrib_PAY_AMT3 | contrib_PAY_AMT4 | contrib_PAY_AMT5 | contrib_PAY_AMT6 | contrib_bias | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1.0 | 0.548391 | 0.451609 | 0.318705 | 0.054260 | 0.024333 | -0.143527 | 0.199437 | 0.123991 | 0.001567 | ... | -0.042873 | 0.004312 | -0.044986 | 0.190008 | 0.116479 | 0.196877 | 0.107893 | 0.060028 | 0.063311 | -1.516447 |
1 | 2.0 | 0.559799 | 0.440201 | 0.011380 | -0.044559 | -0.011563 | 0.017800 | 0.353959 | 0.258357 | -0.009022 | ... | 0.002973 | -0.003932 | -0.034921 | 0.184942 | 0.127812 | -0.081676 | -0.010390 | 0.062603 | -0.015993 | -1.516447 |
2 | 3.0 | 0.913488 | 0.086512 | 0.091553 | -0.073675 | -0.014241 | -0.231872 | -0.036224 | -0.033809 | -0.019079 | ... | -0.013316 | -0.017721 | -0.021681 | 0.091626 | 0.125422 | -0.108036 | -0.012150 | -0.012263 | -0.018186 | -1.516447 |
3 | 4.0 | 0.796132 | 0.203868 | 0.267449 | 0.065499 | 0.019306 | 0.061837 | -0.055391 | -0.033248 | -0.022298 | ... | -0.013313 | -0.033297 | 0.000984 | 0.068004 | -0.016718 | -0.073336 | -0.014324 | -0.039674 | -0.041868 | -1.516447 |
4 | 5.0 | 0.601541 | 0.398459 | 0.170616 | 0.058417 | -0.019828 | 0.940433 | -0.060075 | -0.303138 | -0.018102 | ... | -0.004610 | 0.009174 | -0.005628 | 0.064400 | -0.391913 | -0.065873 | -0.021920 | 0.036659 | 0.023616 | -1.516447 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
994 | 23995.0 | 0.866306 | 0.133694 | 0.478230 | -0.091026 | 0.014865 | -0.215355 | -0.036565 | -0.026022 | -0.020773 | ... | -0.000289 | -0.021694 | 0.008951 | 0.083203 | -0.071253 | -0.044852 | -0.022899 | -0.028537 | 0.018177 | -1.516447 |
995 | 23996.0 | 0.608550 | 0.391450 | 0.087377 | 0.044217 | -0.015629 | 0.014538 | 0.205578 | 0.199663 | -0.011091 | ... | 0.021188 | -0.020175 | 0.056376 | -0.027547 | 0.197609 | -0.037477 | -0.051646 | -0.051575 | 0.029902 | -1.516447 |
996 | 23997.0 | 0.814939 | 0.185061 | 0.536682 | 0.099411 | 0.017427 | -0.208787 | -0.027522 | -0.022646 | -0.023438 | ... | 0.002923 | -0.005027 | -0.000314 | 0.081016 | -0.031194 | -0.071644 | -0.015263 | 0.059949 | -0.030882 | -1.516447 |
997 | 23998.0 | 0.871589 | 0.128411 | 0.481494 | -0.084286 | -0.029002 | -0.224106 | -0.039429 | -0.028018 | -0.022154 | ... | 0.005962 | -0.013858 | -0.035625 | 0.069608 | -0.038320 | -0.066714 | 0.018526 | -0.049960 | -0.024566 | -1.516447 |
998 | 23999.0 | 0.868578 | 0.131422 | 0.461986 | -0.083266 | -0.035072 | -0.229247 | -0.036450 | -0.013597 | -0.024662 | ... | 0.012886 | 0.010888 | -0.066466 | 0.029243 | 0.109742 | -0.081972 | -0.028465 | 0.052664 | 0.036372 | -1.516447 |
23999 rows × 25 columns
Example Usage for Source/Sink
import h2o_mlops_scoring_client
Choose a feature type for contributions - either original or transformed.
CONTRIB_FEATURE_TYPE = h2o_mlops_scoring_client.FeatureType.TRANSFORMED
Pass the feature type when scoring.
ID_COLUMN = "ID"
MLOPS_ENDPOINT_URL = "https://model.internal.dedicated.h2o.ai/65427177-dd10-44dd-abf8-76ab29f60799/model/score"
SOURCE_DATA = "file:///Users/jgranados/datasets/creditcard.csv"
SINK_LOCATION = "file:///Users/jgranados/datasets/output/"
SOURCE_FORMAT = h2o_mlops_scoring_client.Format.CSV
SINK_FORMAT = h2o_mlops_scoring_client.Format.CSV
SINK_WRITE_MODE = h2o_mlops_scoring_client.WriteMode.OVERWRITE
def preprocess(spark_df):
return spark_df.repartition(30)
h2o_mlops_scoring_client.score_source_sink(
mlops_endpoint_url=MLOPS_ENDPOINT_URL,
id_column=ID_COLUMN,
source_data=SOURCE_DATA,
source_format=SOURCE_FORMAT,
sink_location=SINK_LOCATION,
sink_format=SINK_FORMAT,
sink_write_mode=SINK_WRITE_MODE,
preprocess_method=preprocess,
request_contributions=CONTRIB_FEATURE_TYPE
)
23/08/24 16:09:42 INFO h2o_mlops_scoring_client: Connecting to H2O.ai MLOps scorer at 'https://model.internal.dedicated.h2o.ai/65427177-dd10-44dd-abf8-76ab29f60799/model/score'
23/08/24 16:09:45 INFO h2o_mlops_scoring_client: Applying preprocess method
23/08/24 16:09:45 INFO h2o_mlops_scoring_client: Starting scoring from 'file:///Users/jgranados/datasets/creditcard-borked.csv' to 'file:///Users/jgranados/datasets/output/'
23/08/24 16:10:16 INFO h2o_mlops_scoring_client: Scoring complete
23/08/24 16:10:16 INFO h2o_mlops_scoring_client: Total run time: 0:00:36
23/08/24 16:10:16 INFO h2o_mlops_scoring_client: Scoring run time: 0:00:31
Feedback
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai