Skip to main content

Real time scoring

This example demonstrates how to use the eScorer Python client for real time scoring. You can download the complete example here.

Import the H2O eScorer client

import h2o_escorer
import asyncio

Add the async function main to authenticate and score

async def main():
client = Client()

response = await client.realtime_scorer(
model_name='<model_name>',
dataset_filepath='/path/to/dataset.csv',
skip_header=True,
num_rows=1000,
progress=True
)

await client.close()

return response

Call the main function asynchronously

result = asyncio.run(main())
100%|██████████| 1000/1000 [02:15<00:00,  7.39it/s] 

Get the predictions

print(result['predictions'])
              bad_loan.0           bad_loan.1 
0 0.08621099591255188 0.9137890040874481
1 0.08830222487449646 0.9116977751255035
2 0.03488980233669281 0.9651101976633072
3 0.2397906482219696 0.7602093517780304
4 0.4451645463705063 0.5548354536294937
.. ... ...
995 0.15911102294921875 0.8408889770507812
996 0.03693510591983795 0.963064894080162
997 0.25428231060504913 0.7457176893949509
998 0.1850033551454544 0.8149966448545456
999 0.03011934459209442 0.9698806554079056

[1000 rows x 2 columns]

Get the number of rows scored

print(result['rows_produced'])
1000

Get the scoring latency

print(f'{result["time_elapsed"]}s')
135.317s

Feedback