Skip to main content
Version: v0.64.0

Scoring Local Files

Use local file system as source and sink for MLOps batch scoring.



Install the h2o_mlops_scoring_client with pip.


  • 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

import h2o_mlops_scoring_client

Choose the MLOps scoring endpoint.


Set the folders or file (using the file URI) to use along with a unique ID column used to identify each score. Note the source can be either a folder or file while the sink must be a folder.

SOURCE_DATA = "file:///Users/jgranados/datasets/kaggle/bnpparibas/test.csv"
SINK_LOCATION = "file:///Users/jgranados/datasets/output/"

Set the source and sink file type (here we demonstrate CSV).

SOURCE_FORMAT = h2o_mlops_scoring_client.Format.CSV
SINK_FORMAT = h2o_mlops_scoring_client.Format.CSV

Set the sink write mode. Look at the WriteMode value to see its behavior.

'Overwrite existing files'
SINK_WRITE_MODE = h2o_mlops_scoring_client.WriteMode.OVERWRITE

If the file count of the source is small enough, you will want to preprocess the table into partitions to take advantage of parallel scoring. The number of partitions should equal the number of cores times 3. If the file count is larger than the number of cores, repartitioning may slow down scoring, as each individual file will already count as a partition.

def preprocess(spark_df):
return spark_df.repartition(30)

And now we score.

23/04/29 15:50:55 INFO h2o_mlops_scoring_client: Starting Spark context

23/04/29 15:50:55 WARN Utils: Your hostname, M16Max-100638.local resolves to a loopback address:; using instead (on interface en0)
23/04/29 15:50:55 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address

Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).

23/04/29 15:50:56 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
23/04/29 15:50:56 WARN Utils: Service 'SparkUI' could not bind on port 4040. Attempting port 4041.

23/04/29 15:50:56 INFO h2o_mlops_scoring_client: Connecting to MLOps scorer at ''
23/04/29 15:51:00 INFO h2o_mlops_scoring_client: Applying preprocess method
23/04/29 15:51:00 INFO h2o_mlops_scoring_client: Starting scoring from 'file:///Users/jgranados/datasets/kaggle/bnpparibas/test.csv' to 'file:///Users/jgranados/datasets/output/'

23/04/29 15:51:00 WARN package: Truncated the string representation of a plan since it was too large. This behavior can be adjusted by setting 'spark.sql.debug.maxToStringFields'.

23/04/29 15:51:52 INFO h2o_mlops_scoring_client: Scoring complete
23/04/29 15:51:52 INFO h2o_mlops_scoring_client: Total run time: 0:00:57
23/04/29 15:51:52 INFO h2o_mlops_scoring_client: Scoring run time: 0:00:52
23/04/29 15:51:52 INFO h2o_mlops_scoring_client: Stopping Spark context