Connecting Altair Compose with AI hub via Rest API’s

João Marabisa
João Marabisa
Altair Employee
edited March 12 in Altair HyperWorks

With the release of Altair Compose v2023.1 it is possible to use REST API commands in OML language, enabling clients to interact with server side with standard HTTP methods – GET, POST, PATCH, PUT and DELETE using easy to use OML commands webread, webwrite, weboptions.

In this Use Case, users send input commands within Compose, and based on the REST API capabilities, a Real-time scoring agent available on the Altair AI Hub (previously known as RapidMiner AI hub) is accessed, providing predictions in real time back to Compose.

image

Input Data: Specific characteristics of a hotel’s customers, such as age, gender, transaction value and others.

Output Data (prediction): Customer confidence (Churn or Loyal).

Below there is an image showing some of the data used for the algorithm training:

image

To have more details about the model deployment and scoring in a Web application, please access these two videos showing how Altair AI Studio and Altair AI Hub are used: Part 1, Part 2.

Once the model deployment is done, and the endpoints are ready to be accessed, the code below in OML can be executed in Compose to check the confidence of a new customer based on its characteristics:

clc, clear, close all

 

%Inputs

req.Age = 10;

req.AverageTransactionValue = 122.52650653140645;

req.CustomerId = 207;

req.Gender = 'w';

req.MostRecentTransactionDate = 1.14208913634E11;

req.PostalCode = 4;

req.TotalCount = 1;

req.TotalTransactionValue = 122.52650653140645;

req.countPaymentMethod_cash = 1.0;

req.countPaymentMethod_cheque = 0.0;

req.countPaymentMethod_creditcard = 0.0;

 

%AI Hub End Point

URL = 'ENTER HERE YOUR URL';

 

%JSON Format

data = jsonencode(struct('data',{{req}}));

 

%REST commands to send and receive the data

options = weboptions('HeaderFields',struct('Content-Type','application/json'));

out = webwrite(URL, data, options);

 

%Decoding the JSON message

x = jsondecode(out);

f_inrct = intersect(fieldnames(x.data),fieldnames(req));

 

%Prediction values

Predictionvalues = rmfield(x.data,f_inrct);

printf(Predictionvalues.prediction_ChurnIndicator_);

The output of this code is:

image

It means that for this customer’s characteristics the probability it is to have a loyal behavior. The probability can be accessed through the OML Variable Browser:

image

Finally, it is worth mentioning that the JavaScript Object Notation (JSON) format was used to send the message to AI Hub, and for that, JSON commands were used both to code and encode the message.