Skip to content

Inference Request

Makes an Inference Request for a Machine Learning Model.

Prerequisite is to have a Machine Learning Model defined and deployed and a dataset record set up in Machine Learning Models page.

The method accepts the following parameters:

  • response_, out parameter of type CLOB, to which the response will be written.
  • features_attr_, required parameter to specify the features and their values for the request. The format is Attribute String.
  • dataset_id_, required parameter to specify the Dataset ID for the Machine Learning Model.
  • response_format_, optional parameter to specify the response format. Possible values are 'XML', 'JSON' and 'IFS_MESSAGE'. If not specified 'IFS_MESSAGE' will be used as the default format.
  • explain_results_, optional Boolean parameter to specify whether to output inference explanation data.
DECLARE  
   features_attr_ VARCHAR2(32000);  
BEGIN  
   -- Construct attribute string with the features and their values for the Inference Request.   
   Client_SYS.Clear_Attr(features_attr_);  
   Client_SYS.Add_To_Attr('input_feature_1', '<My Feature 1 value>', features_attr_);  
   Client_SYS.Add_To_Attr('input_feature_2', '<My Feature 2 value>', features_attr_);  

   Ml_Util_API.Inference_Request(
      response_        => :response_,      -- Clob parameter to accept response data.
      features_attr_   => features_attr_,  -- Features and their values in attribute string format.
      dataset_id_      => :dataset_id_,    -- Dataset ID for the Machine Learning Model.
      response_format_ => 'XML',           -- Response format ('XML' / 'JSON' / 'IFS_MESSAGE').
      explain_results_ => FALSE );         -- Indicate whether to output explanation data.
END;

For the above call, the response may look as following. The response may vary depending on the IFS Planning & Scheduling Optimization (PSO) version being used.

<DsMachineLearning xmlns="http://tempuri.org/DsMachineLearning.xsd">  
  <ML_Inference_Result>  
    <inference_id>123456</inference_id>  
    <id>0</id>  
    <feature_id>feature_to_predict</feature_id>  
    <value>LOST</value>  
    <probability>0.869461325860953</probability>  
  </ML_Inference_Result>  
  <ML_Inference_Result>  
    <inference_id>123456</inference_id>  
    <id>1</id>  
    <feature_id>feature_to_predict</feature_id>  
    <value>WON</value>  
    <probability>0.130538674139047</probability>  
  </ML_Inference_Result>  
  <ML_Inference>  
    <id>123456</id>  
    <inference_blob_id>123456</inference_blob_id>  
    <row>0</row>  
    <inference_status_id>60</inference_status_id>  
    <request_id>2082</request_id>  
  </ML_Inference>  
  <ML_Inference_Cleaning>  
    <inference_id>123456</inference_id>  
    <id>fe2843ff82ae44e389e7d3a20f6bfa1e</id>  
    <feature_id>input_feature_1</feature_id>  
    <label>Invalidvalue</label>  
    <cleaning_type_id>row_feature_out_of_range</cleaning_type_id>  
  </ML_Inference_Cleaning>  
</DsMachineLearning>

Tip: The IFS Message response format ('IFS_MESSAGE') allows using existing methods in Message_SYS package to handle the response which may be simpler to use in the PL/SQL code than 'XML' or 'JSON'.

For more details about the inference request please see the PSO Machine Learning Guide and the PSO Interface Guide.