API Reference
datarobot_predict.deployment
HttpClient (RESTClientObject)
A temporary class to add TCP keep-alive, once datarobot==3.7 will be published we
can remove this class.
PredictionResult (tuple)
Predicion result type.
dataframe: DataFrame
Result dataframe.
response_headers: CaseInsensitiveDict
Http response headers.
__getnewargs__(self)
special
Return self as a plain tuple. Used by copy and pickle.
__new__(_cls, dataframe, response_headers)
special
staticmethod
Create new instance of PredictionResult(dataframe, response_headers)
__repr__(self)
special
Return a nicely formatted representation string
UnstructuredPredictionResult (tuple)
Unstructured prediction result type.
data: Union[bytes, pandas.core.frame.DataFrame]
Raw response or DataFrame.
response_headers: CaseInsensitiveDict
Http response headers.
__getnewargs__(self)
special
Return self as a plain tuple. Used by copy and pickle.
__new__(_cls, data, response_headers)
special
staticmethod
Create new instance of UnstructuredPredictionResult(data, response_headers)
__repr__(self)
special
Return a nicely formatted representation string
predict(deployment, data_frame, max_explanations=0, max_ngram_explanations=None, threshold_high=None, threshold_low=None, time_series_type=<TimeSeriesType.FORECAST: 1>, forecast_point=None, predictions_start_date=None, predictions_end_date=None, passthrough_columns=None, explanation_algorithm=None, prediction_endpoint=None, timeout=600)
Get predictions using the DataRobot Prediction API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deployment |
Union[datarobot.models.deployment.deployment.Deployment, str] |
DataRobot deployment to use when computing predictions. Deployment can also be specified by deployment id or omitted which is used when prediction_endpoint is set, e.g. when using Portable Prediction Server. If dr.Deployment, the prediction server and deployment id will be taken from the deployment. If str, the argument is expected to be the deployment id. If None, no deployment id is used. This can be used for Portable Prediction Server single-model mode. |
required |
data_frame |
DataFrame |
Input data. |
required |
max_explanations |
Union[int, str] |
Number of prediction explanations to compute. If 0 and 'explanation_algorithm' is set to 'xemp' (default), prediction explanations are disabled. If 0 and 'explanation_algorithm' is set to 'shap', all explanations will be computed. If "all", all explanations will be computed. This is only available for SHAP. |
0 |
max_ngram_explanations |
Union[int, str] |
The maximum number of text prediction explanations to supply per row of the dataset.
The recommended |
None |
threshold_high |
Optional[float] |
Only compute prediction explanations for predictions above this threshold. If None, the default value will be used. |
None |
threshold_low |
Optional[float] |
Only compute prediction explanations for predictions below this threshold. If None, the default value will be used. |
None |
time_series_type |
TimeSeriesType |
Type of time series predictions to compute. If TimeSeriesType.FORECAST, predictions will be computed for a single forecast point specified by forecast_point. If TimeSeriesType.HISTORICAL, predictions will be computed for the range of timestamps specified by predictions_start_date and predictions_end_date. |
<TimeSeriesType.FORECAST: 1> |
forecast_point |
Optional[datetime.datetime] |
Forecast point to use for time series forecast point predictions. If None, the forecast point is detected automatically. If not None and time_series_type is not TimeSeriesType.FORECAST, ValueError is raised |
None |
predictions_start_date |
Optional[datetime.datetime] |
Start date in range for historical predictions. Inclusive. If None, predictions will start from the earliest date in the input that has enough history. If not None and time_series_type is not TimeSeriesType.HISTORICAL, ValueError is raised |
None |
predictions_end_date |
Optional[datetime.datetime] |
End date in range for historical predictions. Exclusive. If None, predictions will end on the last date in the input. If not None and time_series_type is not TimeSeriesType.HISTORICAL, ValueError is raised |
None |
passthrough_columns |
Union[str, Set[str]] |
Columns from the input dataframe to include in with the output. If 'all', all input columns will be included. If None, no columns will be included. |
None |
explanation_algorithm |
Optional[str] |
Which algorithm will be used to calculate prediction explanations. If None, the default value will be used. Note: if 'max_explanations' is set to 0 or is missing, the response will contain - ALL explanation columns, when 'explanation_algorithm' is 'shap'; - NO explanation columns, when 'explanation_algorithm' is 'xemp'. |
None |
prediction_endpoint |
Optional[str] |
Specific prediction endpoint to use. This overrides any prediction server found in deployment. If None, prediction endpoint found in deployment will be used. |
None |
timeout |
int |
Request timeout in seconds. |
600 |
Returns:
Type | Description |
---|---|
PredictionResult |
Prediction result consisting of a dataframe and response headers. |
predict_unstructured(deployment, data, content_type=None, accept=None, timeout=600)
Get predictions for an unstructured model deployment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deployment |
Deployment |
Deployment used to compute predictions. |
required |
data |
Any |
Data to send to the endpoint. This can be text, bytes or a file-like object. Anything that the python requests library accepts as data can be used. If pandas.DataFrame, it will be converted to csv and the response will also be converted to DataFrame if the response content-type is text/csv. |
required |
content_type |
Optional[str] |
The content type for the data. If None, content type will be inferred from data. |
None |
accept |
Optional[str] |
The mimetypes supported for the return value. If None, any mimetype is supported. |
None |
timeout |
int |
Request timeout in seconds. |
600 |
Returns:
Type | Description |
---|---|
UnstructuredPredictionResult |
Prediction result consisting of raw response content and response headers. |
datarobot_predict._base_scoring_code
private
BaseScoringCodeModel (ABC)
class_labels: Optional[Sequence[str]]
property
readonly
Get the class labels for the model.
Returns:
Type | Description |
---|---|
Optional[Sequence[str]] |
List of class labels if model is a classification model, else None. |
date_column: Optional[str]
property
readonly
Get the date column for a Time Series model.
Returns:
Type | Description |
---|---|
Optional[str] |
Name of date column if model has one, else None. |
date_format: Optional[str]
property
readonly
Get the date format for a Time Series model.
Returns:
Type | Description |
---|---|
Optional[str] |
Date format having the syntax expected by datetime.strftime() or None if model is not time series. |
feature_derivation_window: Optional[Tuple[int, int]]
property
readonly
Get the feature derivation window for a Time Series model.
Returns:
Type | Description |
---|---|
Optional[Tuple[int, int]] |
Feature derivation window as (begin, end) if model has this, else None. |
features: Dict[str, type]
property
readonly
Get features names and types for the model.
Returns:
Type | Description |
---|---|
Dict[str, type] |
Dictionary mapping feature name to feature type, where feature type is either str or float. The ordering of features is the same as it was during model training. |
forecast_window: Optional[Tuple[int, int]]
property
readonly
Get the forecast window for a Time Series model.
Returns:
Type | Description |
---|---|
Optional[Tuple[int, int]] |
Forecast window as (begin, end) if model has this, else None. |
model_id: str
property
readonly
Get the model id.
Returns:
Type | Description |
---|---|
str |
The model id. |
model_info: Optional[Dict[str, str]]
property
readonly
Get model metadata.
Returns:
Type | Description |
---|---|
Optional[Dict[str, str]] |
Dictionary with metadata if model has any, else None |
model_type: ModelType
property
readonly
Get the model type.
Returns:
Type | Description |
---|---|
ModelType |
One of: ModelType.CLASSIFICATION, ModelType.REGRESSION, ModelType.TIME_SERIES |
series_id_column: Optional[str]
property
readonly
Get the name of the series id column for a Time Series model.
Returns:
Type | Description |
---|---|
Optional[str] |
Name of the series id column if model has one, else None. |
time_step: Optional[Tuple[int, str]]
property
readonly
Get the time step for a Time Series model.
Returns:
Type | Description |
---|---|
Optional[Tuple[int, str]] |
Time step as (quantity, time unit) if model has this, else None. Example: (3, "DAYS") |
ModelType (Enum)
An enumeration.
CLASSIFICATION
Classification predictor
GENERIC
Generic predictor. Used for testing purposes.
REGRESSION
Regression predictor
TIME_SERIES
Time Series predictor
datarobot_predict.scoring_code
ScoringCodeModel (BaseScoringCodeModel)
__init__(self, jar_path)
special
Constructor for ScoringCodeModel
Parameters:
Name | Type | Description | Default |
---|---|---|---|
jar_path |
str |
path to a jar file |
required |
predict(self, data_frame, max_explanations=0, threshold_high=None, threshold_low=None, time_series_type=<TimeSeriesType.FORECAST: 1>, forecast_point=None, predictions_start_date=None, predictions_end_date=None, prediction_intervals_length=None, passthrough_columns=None)
Get predictions from Scoring Code model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_frame |
pd.DataFrame |
Input data. |
required |
max_explanations |
int |
Number of prediction explanations to compute. If 0, prediction explanations are disabled. |
0 |
threshold_high |
Optional[float] |
Only compute prediction explanations for predictions above this threshold. If None, the default value will be used. |
None |
threshold_low |
Optional[float] |
Only compute prediction explanations for predictions below this threshold. If None, the default value will be used. |
None |
time_series_type |
TimeSeriesType |
Type of time series predictions to compute. If TimeSeriesType.FORECAST, predictions will be computed for a single forecast point specified by forecast_point. If TimeSeriesType.HISTORICAL, predictions will be computed for the range of timestamps specified by predictions_start_date and predictions_end_date. |
<TimeSeriesType.FORECAST: 1> |
forecast_point |
Optional[datetime.datetime] |
Forecast point to use for time series forecast point predictions. If None, the forecast point is detected automatically. If not None and time_series_type is not TimeSeriesType.FORECAST, ValueError is raised |
None |
predictions_start_date |
Optional[datetime.datetime] |
Start date in range for historical predictions. Inclusive. If None, predictions will start from the earliest date in the input that has enough history. If not None and time_series_type is not TimeSeriesType.HISTORICAL, ValueError is raised |
None |
predictions_end_date |
Optional[datetime.datetime] |
End date in range for historical predictions. Exclusive. If None, predictions will end on the last date in the input. If not None and time_series_type is not TimeSeriesType.HISTORICAL, ValueError is raised |
None |
prediction_intervals_length |
Optional[int] |
The percentile to use for the size for prediction intervals. Has to be an integer between 0 and 100(inclusive). If None, prediction intervals will not be computed. |
None |
passthrough_columns |
Union[str, Set[str], None] |
Columns from the input dataframe to include in with the output. If 'all', all input columns will be included. If None, no columns will be included. |
None |
Returns:
Type | Description |
---|---|
pd.DataFrame |
Prediction output. |
datarobot_predict.spark_scoring_code
SparkScoringCodeModel (BaseScoringCodeModel)
__init__(self, jar_path=None, allow_models_in_classpath=False)
special
Create a new instance of SparkScoringCodeModel
Parameters:
Name | Type | Description | Default |
---|---|---|---|
jar_path |
Optional[str] |
The path to a Scoring Code jar file to load. If None, the Scoring Code jar will be loaded from the classpath |
None |
allow_models_in_classpath |
bool |
Having models in the classpath while loading a model from the filesystem using the jar_path argument can lead to unexpected behavior so this is not allowed by default but can be forced using allow_models_in_classpath. If True, models already present in the classpath will be ignored. If False, a ValueError will be raised if models are detected in the classpath. |
False |
predict(self, data_frame, time_series_type=<TimeSeriesType.FORECAST: 1>, forecast_point=None, predictions_start_date=None, predictions_end_date=None)
Get predictions from the Scoring Code Spark model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_frame |
Union[pyspark.sql.dataframe.DataFrame, pandas.core.frame.DataFrame] |
Input data. |
required |
time_series_type |
TimeSeriesType |
Type of time series predictions to compute. If TimeSeriesType.FORECAST, predictions will be computed for a single forecast point specified by forecast_point. If TimeSeriesType.HISTORICAL, predictions will be computed for the range of timestamps specified by predictions_start_date and predictions_end_date. |
<TimeSeriesType.FORECAST: 1> |
forecast_point |
Optional[datetime.datetime] |
Forecast point to use for time series forecast point predictions. If None, the forecast point is detected automatically. If not None and time_series_type is not TimeSeriesType.FORECAST, ValueError is raised |
None |
predictions_start_date |
Optional[datetime.datetime] |
Start date in range for historical predictions. Inclusive. If None, predictions will start from the earliest date in the input that has enough history. If not None and time_series_type is not TimeSeriesType.HISTORICAL, ValueError is raised |
None |
predictions_end_date |
Optional[datetime.datetime] |
End date in range for historical predictions. Exclusive. If None, predictions will end on the last date in the input. If not None and time_series_type is not TimeSeriesType.HISTORICAL, ValueError is raised |
None |
Returns:
Type | Description |
---|---|
DataFrame |
Prediction output. |