Predictions

class datarobot.models.Predictions(project_id, prediction_id, model_id=None, dataset_id=None, includes_prediction_intervals=None, prediction_intervals_size=None, forecast_point=None, predictions_start_date=None, predictions_end_date=None, actual_value_column=None, explanation_algorithm=None, max_explanations=None, shap_warnings=None)

Represents predictions metadata and provides access to prediction results.

Examples

List all predictions for a project

import datarobot as dr

# Fetch all predictions for a project
all_predictions = dr.Predictions.list(project_id)

# Inspect all calculated predictions
for predictions in all_predictions:
    print(predictions)  # repr includes project_id, model_id, and dataset_id

Retrieve predictions by id

import datarobot as dr

# Getting predictions by id
predictions = dr.Predictions.get(project_id, prediction_id)

# Dump actual predictions
df = predictions.get_all_as_dataframe()
print(df)
Attributes:
project_idstr

id of the project the model belongs to

model_idstr

id of the model

prediction_idstr

id of generated predictions

includes_prediction_intervalsbool, optional

(New in v2.16) For time series projects only. Indicates if prediction intervals will be part of the response. Defaults to False.

prediction_intervals_sizeint, optional

(New in v2.16) For time series projects only. Indicates the percentile used for prediction intervals calculation. Will be present only if includes_prediction_intervals is True.

forecast_pointdatetime.datetime, optional

(New in v2.20) For time series projects only. This is the default point relative to which predictions will be generated, based on the forecast window of the project. See the time series prediction documentation for more information.

predictions_start_datedatetime.datetime or None, optional

(New in v2.20) For time series projects only. The start date for bulk predictions. Note that this parameter is for generating historical predictions using the training data. This parameter should be provided in conjunction with predictions_end_date. Can’t be provided with the forecast_point parameter.

predictions_end_datedatetime.datetime or None, optional

(New in v2.20) For time series projects only. The end date for bulk predictions, exclusive. Note that this parameter is for generating historical predictions using the training data. This parameter should be provided in conjunction with predictions_start_date. Can’t be provided with the forecast_point parameter.

actual_value_columnstring, optional

(New in version v2.21) For time series unsupervised projects only. Actual value column which was used to calculate the classification metrics and insights on the prediction dataset. Can’t be provided with the forecast_point parameter.

explanation_algorithmdatarobot.enums.EXPLANATIONS_ALGORITHM, optional

(New in version v2.21) If set to ‘shap’, the response will include prediction explanations based on the SHAP explainer (SHapley Additive exPlanations). Defaults to null (no prediction explanations).

max_explanationsint, optional

(New in version v2.21) The maximum number of explanation values that should be returned for each row, ordered by absolute value, greatest to least. If null, no limit. In the case of ‘shap’: if the number of features is greater than the limit, the sum of remaining values will also be returned as shapRemainingTotal. Defaults to null. Cannot be set if explanation_algorithm is omitted.

shap_warningsdict, optional

(New in version v2.21) Will be present if explanation_algorithm was set to datarobot.enums.EXPLANATIONS_ALGORITHM.SHAP and there were additivity failures during SHAP values calculation.

classmethod list(project_id, model_id=None, dataset_id=None)

Fetch all the computed predictions metadata for a project.

Parameters:
project_idstr

id of the project

model_idstr, optional

if specified, only predictions metadata for this model will be retrieved

dataset_idstr, optional

if specified, only predictions metadata for this dataset will be retrieved

Returns:
A list of Predictions objects
Return type:

List[Predictions]

classmethod get(project_id, prediction_id)

Retrieve the specific predictions metadata

Parameters:
project_idstr

id of the project the model belongs to

prediction_idstr

id of the prediction set

Returns:
Predictions object representing specified
predictions
Return type:

Predictions

get_all_as_dataframe(class_prefix='class_', serializer='json')

Retrieve all prediction rows and return them as a pandas.DataFrame.

Parameters:
class_prefixstr, optional

The prefix to append to labels in the final dataframe. Default is class_ (e.g., apple -> class_apple)

serializerstr, optional

Serializer to use for the download. Options: json (default) or csv.

Returns:
dataframe: pandas.DataFrame
Raises:
datarobot.errors.ClientError

if the server responded with 4xx status.

datarobot.errors.ServerError

if the server responded with 5xx status.

Return type:

DataFrame

download_to_csv(filename, encoding='utf-8', serializer='json')

Save prediction rows into CSV file.

Parameters:
filenamestr or file object

path or file object to save prediction rows

encodingstring, optional

A string representing the encoding to use in the output file, defaults to ‘utf-8’

serializerstr, optional

Serializer to use for the download. Options: json (default) or csv.

Return type:

None

PredictionServer

class datarobot.PredictionServer(id=None, url=None, datarobot_key=None)

A prediction server can be used to make predictions.

Attributes:
idstr, optional

The id of the prediction server.

urlstr

The url of the prediction server.

datarobot_keystr, optional

The Datarobot-Key HTTP header used in requests to this prediction server. Note that in the datarobot.models.Deployment instance there is the default_prediction_server property which has this value as a “kebab-cased” key as opposed to “snake_cased”.

classmethod list()

Returns a list of prediction servers a user can use to make predictions. :rtype: List[PredictionServer]

Added in version v2.17.

Returns:
prediction_serverslist of PredictionServer instances

Contains a list of prediction servers that can be used to make predictions.

Examples

prediction_servers = PredictionServer.list()
prediction_servers
>>> [PredictionServer('https://example.com')]