Skip to content

Machine Learning Interfaces

The package Ml_Util_API has the following public methods that can be used to communicate with the Machine Learning service on the IFS Planning & Scheduling Optimization (PSO) server. Prerequisite is to have a Machine Learning Model defined and deployed and a dataset record set up in Machine Learning Models page.

  • Get Model Statistics
  • Inference Request

Get Model Statistics

Returns the status and other details of a machine learning model. The method accepts three parameters:

  • response_, out parameter of type CLOB, to which the response will be written.
  • 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.
BEGIN  
  Ml_Util_API.Get_Model_Statistics(response_        => :response_,     -- Clob parameter to accept response data  
                                   dataset_id_      => :dataset_id_,   -- Dataset ID for the Machine Learning Model  
                                   response_format_ => 'XML');         -- Response format ('XML' / 'JSON' / 'IFS_MESSAGE')  
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. For more details about retrieving model statistics please see the PSO Machine Learning Guide and the PSO Interface Guide.

<DsMachineLearning xmlns="http://tempuri.org/DsMachineLearning.xsd">  
  <ML_Model>  
    <id>Machine_Learning_Demo_Model</id>  
    <feature_id>feature_to_predict</feature_id>  
    <update_datetime>2021-03-18T12:00:00+00:00</update_datetime>  
    <model_status_id>10</model_status_id>  
    <algorithm>DecisionTree</algorithm>  
    <problem_type>Classification</problem_type>  
  </ML_Model>  
  <ML_Model_Range>  
    <id>0</id>  
    <feature_id>feature_to_predict</feature_id>  
    <value>WON</value>  
    <active>true</active>  
  </ML_Model_Range>  
  <ML_Model_Range>  
    <id>0</id>  
    <feature_id>input_feature_1</feature_id>  
    <value>ABC</value>  
    <active>true</active>  
  </ML_Model_Range>  
...  
  <ML_Model_Score>  
    <id>f1_macro</id>  
    <value>0.774174337284988</value>  
  </ML_Model_Score>  
  <ML_Model_Score>  
    <id>f1_weighted</id>  
    <value>0.831843645620681</value>  
  </ML_Model_Score>  
  <ML_Model_Score>  
    <id>iterations</id>  
    <value>51</value>  
  </ML_Model_Score>  
...  
  <ML_Model_Cleaning>  
    <id>e02c8e395d40457ba8336f31f2b02bd7</id>  
    <feature_id>input_feature_1</feature_id>  
    <label>OTHER</label>  
    <cleaning_type_id>label_counts_too_low</cleaning_type_id>  
  </ML_Model_Cleaning>  
</DsMachineLearning>

Inference Request

Makes an Inference request for a machine learning model. The method accepts five 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. For more details about the inference request please see the PSO Machine Learning Guide and the PSO Interface Guide.

<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'.