Predicting

Predicting with Scikit-Learn Models

When your model is fully deployed, predictions may be received with a POST request to the /sklearn/predict endpoint. Prediction requests with multi-region accounts will be latency-routed to the closest data center to achieve the lowest response times.

Features must be provided to the endpoint as a 2D array with numerical values. For single predictions, provide a single nested array (e.g., [[1, 2, 3]]). For multiple predictions, provide multiple nested arrays (e.g., [[1, 2, 3], [4, 5, 6], [7, 8, 9]]).

Single-Datacenter Predictions

To obtain a prediction from a single datacenter with a free or single-region account, you must provide the region when predicting. You can specify the region using the regions available in mlrequest-python or by using a regional API endpoint.

mlrequest-python Regions

  • regions.US_WEST (N. California)

  • regions.US_EAST (Ohio)

  • regions.EU_CENTRAL (Frankfurt)

  • regions.AP_SOUTH (Mumbai)

  • regions.AP_NORTHEAST (Seoul)

Regional API

  • https://api.us-west.mlrequest.com (N. California)

  • https://api.us-east.mlrequest.com (Ohio)

  • https://api.eu-central.mlrequest.com (Frankfurt)

  • https://api.ap-south.mlrequest.com (Mumbai)

  • https://api.ap-northeast.mlrequest.com (Seoul)

You must provide a region if you have a free or single-region account. Otherwise, a datacenter will somewhat arbitrarily be chosen and your prediction requests may be rejected.

Below is an example of a single prediction. The response field predict_result will be an array with a single value (the same way scikit-learn will return a prediction).

Python Client
Python
Javascript
Java
Go
Ruby
C#
from mlrequest import SKLearn
from mlrequest import regions
sklearn = SKLearn('your-api-key')
features = [[1, 2, 3]]
r = sklearn.predict(features, 'rf-classifier', regions.US_EAST)
predictions = r.predict_result
features = [[1, 2, 3]]
payload = {
'features': features,
'model_name': 'rf-classifier'
}
r = requests.post('https://api.us-east.mlrequest.com/v1/sklearn/predict', json=payload, headers={'MLREQ-API-KEY':'your-api-key'})
predictions = r.json()['predict_result']
Coming soon.
Coming soon.
Coming soon.
Coming soon.
Coming soon.

To receive multiple predictions in one request, add more arrays of features. The response field predict_result will be an array with the same number of values as provided feature arrays.

Python Client
Python
Javascript
Java
Go
Ruby
C#
features = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
r = sklearn.predict(features, 'rf-classifier', regions.US_EAST)
predictions = r.predict_result
features = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
payload = {
'features': features,
'model_name': 'rf-classifier'
}
r = requests.post('https://api.us-east.mlrequest.com/v1/sklearn/predict', json=payload, headers={'MLREQ-API-KEY':'your-api-key'})
predictions = r.json()['predict_result']
Coming soon.
Coming soon.
Coming soon.
Coming soon.
Coming soon.

Latency-Routed Predictions

To obtain latency-routed predictions with a multi-region account, you do not need to specify a region. You may provide a region if you do not want to receive latency-routed predictions, however. Use the https://api.mlrequest.com API URL when not using mlrequest-python.

Same as above, the response field predict_result will be an array with the same number of predictions as provided feature vectors.

Python Client
Python
Javascript
Java
Go
Ruby
C#
from mlrequest import SKLearn
sklearn = SKLearn('your-api-key')
features = [[1, 2, 3]]
r = sklearn.predict(features, 'rf-classifier')
predictions = r.predict_result
features = [[1, 2, 3]]
payload = {
'features': features,
'model_name': 'rf-classifier'
}
r = requests.post('https://api.mlrequest.com/v1/sklearn/predict', json=payload, headers={'MLREQ-API-KEY':'your-api-key'})
predictions = r.json()['predict_result']
Coming soon.
Coming soon.
Coming soon.
Coming soon.
Coming soon.