Deployed model

Prevision.io’s SDK allows to make a prediction from a model deployed with the Prevision.io’s platform.

import previsionio as pio

# Initialize the deployed model object from the url of the model, your client id and client secret for this model, and your credentials
model = pio.DeployedModel(prevision_app_url, client_id, client_secret)

# Make a prediction
prediction, confidance, explain = model.predict(
    predict_data={'feature1': 1, 'feature2': 2},
    use_confidence=True,
    explain=True,
)
class previsionio.deployed_model.DeployedModel(prevision_app_url: str, client_id: str, client_secret: str, prevision_token_url: str = None)

DeployedModel class to interact with a deployed model.

predict(predict_data: Dict, use_confidence: bool = False, explain: bool = False)

Get a prediction on a single instance using the best model of the usecase.

Parameters:
  • predict_data (dictionary) – input data for prediction
  • confidence (bool, optional) – Whether to predict with confidence values (default: False)
  • explain (bool) – Whether to explain prediction (default: False)
Returns:

Tuple containing the prediction value, confidence and explain. In case of regression problem type, confidence format is a list. In case of multiclassification problem type, prediction value format is a string.

Return type:

tuple(float, float, dict)

request(endpoint, method, files=None, data=None, allow_redirects=True, content_type=None, no_retries=False, **requests_kwargs)

Make a request on the desired endpoint with the specified method & data.

Requires initialization.

Parameters:
  • endpoint – (str): api endpoint (e.g. /usecases, /prediction/file)
  • method (requests.{get,post,delete}) – requests method
  • files (dict) – files dict
  • data (dict) – for single predict
  • content_type (str) – force request content-type
  • allow_redirects (bool) – passed to requests method
  • no_retries (bool) – force request to run the first time, or exit directly
Returns:

request response

Raises:

Exception – Error if url/token not configured