batch-scoring
batch-scoring copied to clipboard
Batch scoring script for making predictions
datarobot_batch_scoring
A script to score CSV files via DataRobot's prediction API.
.. image:: https://coveralls.io/repos/github/datarobot/batch-scoring/badge.svg?branch=master :target: https://coveralls.io/github/datarobot/batch-scoring?branch=master
.. image:: https://travis-ci.com/datarobot/batch-scoring.svg?branch=master :target: https://travis-ci.com/datarobot/batch-scoring#master
.. image:: https://badge.fury.io/py/datarobot-batch-scoring.svg :target: https://badge.fury.io/py/datarobot-batch-scoring
Deprecation Notice
The Batch Scoring script is deprecated. It will continue functioning indefinitely, but it will not receive any new bug fixes and new functionality. Please, use the [Batch Prediction command-line tools](https://app.datarobot.com/docs/predictions/batch/cli-scripts.html] instead.
Version Compatibility
We aim to support as many versions of DataRobot as possible with each release of batch_scoring, but occasionally there are changes in the backend that create incompatibilities. This chart is kept up-to-date with the version compatibilities between this tool and versions of DataRobot. If you are unsure which version of DataRobot you are using, please contact DataRobot support for assistance.
===================== ================= batch_scoring_version DataRobot Version
<=1.10 2.7, 2.8, 2.9
=1.11, <1.13 3.0, 3.1+ =1.13 2.7, 2.8, 2.9, 3.0, 3.1+ ===================== =================
Command batch_scoring_deployment_aware available only for new DataRobot
versions.
============================== ================= batch_scoring_deployment_aware DataRobot Version
=1.14 4.4+ ============================== =================
How to install
Install or upgrade to last version: ::
$ pip install -U datarobot_batch_scoring
How to install particular version: ::
$ pip install datarobot_batch_scoring==x.y.z
Alternative Installs
We publish two alternative install methods on our releases_ page. These are for situations where internet is restricted or Python is unavailable.
:offlinebundle: For performing installations in environments where Python2.7 or Python3+ is available, but there is no access to the internet. Does not require administrative privileges or pip. Works on Linux, OSX or Windows.
These files have "offlinebundle" in their name on the release page.
:PyInstaller: Using pyinstaller_ we build a single-file-executable that does not depend on Python. It only depends on libc and can be installed without administrative privileges. Right now we publish builds that work for most Linux distros made since Centos5. OSX and Windows are also supported.
These files have "executables" in their name on the release page.
.. _releases: https://github.com/datarobot/batch-scoring/releases .. _pyinstaller: http://www.pyinstaller.org/
Features
- Concurrent requests (
--n_concurrent) - Pause/resume
- Gzip support
- Custom delimiters
- Parallel processing
Deprecation warning
The batch_scoring command is deprecated because the following API routes that are used by this command are
deprecated:
/api/v1//predApi/v1.0/<projectId>/<modelId>/
Instead, use batch_scoring_deployment_aware command since /predApi/v1.0/deployments/<deploymentId>/ is
the only supported endpoint for prediction servers.
Running the batch_scoring, batch_scoring_sse scripts or batch_scoring_deployment_aware
You can execute the batch_scoring_deployment_aware, batch_scoring_sse or batch_scoring (deprecated)
command from the command line with relevant parameters or you can pass parameters to a script from the .ini file.
Place the .ini file in your home directory or the directory from which you are running the
batch_scoring_deployment_aware, batch_scoring_sse or batch_scoring (deprecated) command. Use the syntax
and arguments below to define the parameters. Note that if you run the script and also execute via the command line,
the command line parameters take priority.
The following table describes the syntax conventions; the syntax for running the script follows the table. DataRobot supplies two scripts, each for a different application. Use:
batch_scoring_deployment_awareto score on dedicated prediction instances usingdeployment_idinstead ofproject_idandmodel_id.batch_scoring_sseto score on standalone prediction instances. If you are unsure of your instance type, contactDataRobot Support <https://support.datarobot.com/hc/en-us>_.batch_scoring(deprecated) to score on dedicated prediction instances usingproject_idandmodel_id.
============ ======= Convention Meaning
[ ] Optional argument < > User supplied value { | } Required, mutually exclusive ============ =======
Required arguments:
batch_scoring_deployment_aware --host=<host> --user=<user> <deployment_id> <dataset_filepath> --datarobot_key=<datarobot_key> {--password=<pwd> | --api_token=<api_token>}
batch_scoring_sse --host=<host> <import_id> <dataset_filepath>
(deprecated) batch_scoring --host=<host> --user=<user> <project_id> <model_id> <dataset_filepath> --datarobot_key=<datarobot_key> {--password=<pwd> | --api_token=<api_token>}
Additional recommended arguments:
[--verbose] [--keep_cols=<keep_cols>] [--n_concurrent=<n_concurrent>]
Additional optional arguments:
[--out=<filepath>] [--api_version=<api_version>] [--pred_name=<string>] [--timeout=<timeout>] [—-create_api_token] [--n_retry=<n_retry>] [--delimiter=<delimiter>] [--resume] [--no-resume] [--skip_row_id] [--output_delimiter=<delimiter>]
Argument descriptions: The following table describes each of the arguments:
================================== ========== ========= =========== Argument Standalone Dedicated Description
host=<host> using project <project_id> and model <model_id>.
datarobot_key=<datarobot_key> - + An additional datarobot_key for dedicated prediction instances. This argument is required when using on-demand workers on the Cloud platform, but not for Enterprise users.
password=api_token argument instead.
api_token=<api_token> - + Specifies the API token for requests; if you do not have a token, you must specify the password argument. You can retrieve your token from your profile on the My Account page.
out=out.csv, written to the directory containing the script. The value of the output file must be a single .csv file that can be gzipped (extension .gz).
verbose + + Provides status updates while the script is running. It is recommended that you include this argument to track script execution progress. Silent mode (non-verbose), the default, displays very little output.
keep_cols=<keep_cols> + + Specifies the column names to append to the predictions. Enter as a comma-separated list.
max_prediction_explanations=0.
n_samples=<n_samples> + + Specifies the number of samples (rows) to use per batch. If not defined, the auto_sample option is used.
n_concurrent=<n_concurrent> + + Specifies the number of concurrent requests to submit. By default, the script submits four concurrent requests. Set <n_concurrent> to match the number of cores in the prediction API endpoint.
n_retry=<n_retry> + + Specifies the number of times DataRobot will retry if a request fails. A value of -1, the default, specifies an infinite number of retries.
pred_name=<pred_name> + + Applies a name to the prediction column of the output file. If you do not supply the argument, the column name is blank. For binary predictions, only positive class columns are included in the output. The last class (in lexical order) is used as the name of the prediction column.
skip_row_id + + Skip the row_id column in output.
output_delimiter=<n_retry>. The default value is 30 seconds.
delimiter=resume argument. If you do not include this argument, and the script detects a previous script was interrupted mid-execution, DataRobot prompts whether to resume. When resuming a script, you cannot change the dataset_filepath, model_id, project_id, n_samples, or keep_cols.
no-resume + + Starts the prediction from scratch disregarding previous run.
help + + Shows usage help for the command.
fast + + Experimental: Enables a faster .csv processor. Note that this method does not support multiline CSV files.
stdout + + Sends all log messages to stdout. If not specified, the command sends log messages to the datarobot_batch_scoring_main.log file.
auto_sample + + Override the <n_samples> value and instead uses chunks of roughly 2.5 MB to improve throughput. Enabled by default.
encoding + + Specifies dataset encoding. If not provided, the batch_scoring or batch_scoring_sse script attempts to detect the decoding (e.g., "utf-8", "latin-1", or "iso2022_jp"). See the Python standard encodings <https://docs.python.org/3/library/codecs.html#standard-encodings>_ for a list of valid values.
skip_dialect + + Specifies that the script skips CSV dialect detection and uses default "excel" dialect for CSV parsing. By default, the scripts do detect CSV dialect for proper batch generation on the client side.
ca_bundle=<ca_bundle> + + Specifies the path to a CA_BUNDLE file or directory with certificates of trusted Certificate Authorities (CAs) to be used for SSL verification.
Note: if passed a path to a directory, the directory must have been processed using the c_rehash utility supplied with OpenSSL.
no_verify_ssl + + Disable SSL verification.
================================== ========== ========= ===========
Example::
batch_scoring_deployment_aware --host=https://mycorp.orm.datarobot.com/ --user="[email protected]" --out=pred.csv 5545eb71b4912911244d4848 /home/greg/Downloads/diabetes_test.csv
batch_scoring_sse --host=https://mycorp.orm.datarobot.com/ --out=pred.csv 0ec5bcea7f0f45918fa88257bfe42c09 /home/greg/Downloads/diabetes_test.csv
batch_scoring --host=https://mycorp.orm.datarobot.com/ --user="[email protected]" --out=pred.csv 5545eb20b4912911244d4835 5545eb71b4912911244d4847 /home/greg/Downloads/diabetes_test.csv
Using the configuration file
The batch_scoring command checks for the existence of a batch_scoring.ini file at the directory where you are running the script (working directory) and, if it is not found in the working directory, in $HOME/batch_scoring.ini (your home directory). If this file exists, the command uses the same arguments as those described above. If the file does not exist, the command proceeds normally with the command line arguments. The command line arguments have higher priority than the file arguments (that is, you can override file arguments using the command line).
The format of a batch_scoring.ini file is as follows::
[batch_scoring] host=file_host project_id=file_project_id model_id=file_model_id user=file_username
Usage Notes
- If the script detects that a previous script was interrupted in mid-execution, it will prompt whether to resume that execution.
- If no interrupted script was detected or if you indicate not to resume the previous execution, the script checks to see if the specified output file exists. If yes, the script prompts to confirm before overwriting this file.
- The logs from each
batch_scoring_deployment_aware,batch_scoring_sseandbatch_scoringrun are stored in the current working directory. All users see adatarobot_batch_scoring_main.loglog file. Windows users see two additional log files,datarobot_batch_scoring_batcher.loganddatarobot_batch_scoring_writer.log. - Batch scoring won't work if there is only 1 feature in the scoring data. This issue is caused by limitations of standard python CSV parser. For resolving this issue, please add index column to the dataset - it'll be ignored in scoring, but will help it in parsing.
Supported Platforms
datarobot_batch_scoring is tested on Linux and Windows and OS X. Both Python 2.7.x and Python 3.x are supported.
Recommended Python Version
Python 3.5 or greater is recommended, but all versions of Python 3 should work. Python 2.7.x. will work, but it sometimes errors decoding data that Python 3 handles gracefully. Python 3 is also faster.
Proxy support
batch-scoring script handles standart HTTP_PROXY, HTTPS_PROXY, NO_PROXY environment variables::
export HTTP_PROXY=http://192.168.1.3:3128 export HTTPS_PROXY=http://192.168.1.3:3128 export NO_PROXY=noproxy.domain.com