Predictions
- class datarobot.models.Predictions
Represents predictions metadata and provides access to prediction results.
- Variables:
project_id (
str
) – id of the project the model belongs tomodel_id (
str
) – id of the modelprediction_id (
str
) – id of generated predictionsincludes_prediction_intervals (
Optional[bool]
) – (New in v2.16) For time series projects only. Indicates if prediction intervals will be part of the response. Defaults to False.prediction_intervals_size (
Optional[int]
) – (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_point (
datetime.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_date (
datetime.datetime
orNone
, 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 withpredictions_end_date
. Can’t be provided with theforecast_point
parameter.predictions_end_date (
datetime.datetime
orNone
, 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 withpredictions_start_date
. Can’t be provided with theforecast_point
parameter.actual_value_column (
string
, 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 theforecast_point
parameter.explanation_algorithm (
datarobot.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_explanations (
Optional[int]
) – (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_warnings (
dict
, 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.
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)
- classmethod list(project_id, model_id=None, dataset_id=None)
Fetch all the computed predictions metadata for a project.
- Parameters:
project_id (
str
) – id of the projectmodel_id (
Optional[str]
) – if specified, only predictions metadata for this model will be retrieveddataset_id (
Optional[str]
) – if specified, only predictions metadata for this dataset will be retrieved
- Return type:
A list
ofPredictions
objects
- classmethod get(project_id, prediction_id)
Retrieve the specific predictions metadata
- Parameters:
project_id (
str
) – id of the project the model belongs toprediction_id (
str
) – id of the prediction set
- Return type:
- Returns:
Predictions
object representing specifiedpredictions
- get_all_as_dataframe(class_prefix='class_', serializer='json')
Retrieve all prediction rows and return them as a pandas.DataFrame.
- Parameters:
class_prefix (
Optional[str]
) – The prefix to append to labels in the final dataframe. Default isclass_
(e.g., apple -> class_apple)serializer (
Optional[str]
) – Serializer to use for the download. Options:json
(default) orcsv
.
- Returns:
dataframe
- Return type:
pandas.DataFrame
- Raises:
datarobot.errors.ClientError – if the server responded with 4xx status.
datarobot.errors.ServerError – if the server responded with 5xx status.
- download_to_csv(filename, encoding='utf-8', serializer='json')
Save prediction rows into CSV file.
- Parameters:
filename (
str
orfile object
) – path or file object to save prediction rowsencoding (
string
, optional) – A string representing the encoding to use in the output file, defaults to ‘utf-8’serializer (
Optional[str]
) – Serializer to use for the download. Options:json
(default) orcsv
.
- Return type:
None
PredictionServer
- class datarobot.PredictionServer
A prediction server can be used to make predictions.
- Variables:
id (
Optional[str]
) – The id of the prediction server.url (
str
) – The url of the prediction server.datarobot_key (
Optional[str]
) – TheDatarobot-Key
HTTP header used in requests to this prediction server. Note that in thedatarobot.models.Deployment
instance there is thedefault_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.
Added in version v2.17.
- Returns:
prediction_servers – Contains a list of prediction servers that can be used to make predictions.
- Return type:
list
ofPredictionServer instances
Examples
prediction_servers = PredictionServer.list() prediction_servers >>> [PredictionServer('https://example.com')]