Make Predictions

cancel
Showing results for 
Search instead for 
Did you mean: 

Make Predictions

If you have created a deployment that acts as an endpoint to the model that you want to use, then you can make predictions with curl commands from the REST API or using our Python SDK.

To find more information about making predictions from the terminal, see the in-app documentation (How to: Prediction API topic.) You can find our full Python module documentation here.

You can get the sample code for this workflow and snippets in DataRobot Community GitHub.

Make Predictions from the Terminal

Requirements

  • Deployment—a model that you or someone else has already deployed. Learn to do this here.
  • endpoint_url—the URL to your endpoint. You can find this on the Deployments > Overview tab.
  • api_key—found in your profile in the platform.
  • datarobot-key—you can find this in the code found on the DeploymentsIntegrations tab. This is only necessary if you are using Managed AI Cloud.
  • deploymentId—you can find this number in the URL of the deployment. It is also returned to you when you create the deployment with a curl request.
  • Filepath.csv—your file path to the data you want to make predictions on.

Terminal Request

curl -v \
-X POST \
PRED_ENDPOINT \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "datarobot-key: YOUR_DATAROBOT_KEY" \
-H "Content-Type: application/json" \ (this could be also CSV)
--data-raw JSON_PAYLOAD


Example Request

API_KEY=YOUR_API_KEY
DATAROBOT_KEY=YOUR_DATAROBOT_KEY
DEPLOYMENT_ID=YOUR_DEPLOYMENT_ID
JSON_PAYLOAD=YOUR_JSON_PAYLOAD
ENDPOINT_URL=YOUR_ENDPOINT_URL
PRED_ENDPOINT=$YOUR_DR_URL/predApi/v1.0/deployments/$DEPLOYMENT_ID/predictions

curl -v \
-X POST \
ENDPOINT_URL \
-H "Authorization: Bearer $API_KEY" \
-H "datarobot-key: $DATAROBOT_KEY" \
-H "Content-Type: application/json" \
--data-raw $JSON_PAYLOAD

Example JSON payload

[
    {
        "feature_1": "value",
        "some_other_feature": 42,
        "a_boolean_feature": true,
        ...
    },
    ...
]

Make Predictions using Python

Requirements

  • API Key—profile in the platform
  • Import DataRobot Package and be connected to DataRobot (learn here)
  • A completed model—either built by you or someone else (learn here)

The following information for the completed model:

  • The project ID—you can find this in the URL of the model (first number)
    For example: app.datarobot.com/projects/<projectId>/models/<modelId>blueprint
  • The model ID—you can find this in the URL of the model (second number)
    For example: app.datarobot.com/projects/<projectId>/models/<modelId>blueprint
  • filepath—path to file you want to score

Score

import datarobot as dr

project_id = ‘<projectId>’
model_id = ‘<modelId>’
project = dr.Project.get(project_id) 
model = dr.Model.get(project=project_id, model_id=model_id)
					
dataset_from_path = project.upload_dataset('<filepath>')
						
predict_job = model.request_predictions(dataset_from_path.id) 


Example

 
import datarobot as dr

project_id = '5505fcd42bd88f5953219da0' 
model_id = '5505fcd42bd88f1641a720a3'
project = dr.Project.get(project_id) 
model = dr.Model.get(project=project_id, model_id=model_id)
					
dataset_from_path = project.upload_dataset('./data_to_predict.csv')

predict_job = model.request_predictions(dataset_from_path.id) 
Labels (3)
Version history
Last update:
‎04-15-2020 05:06 PM
Updated by:
Contributors