Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Let's add an input event stream definition to capture the events generated by the supplier before shipping the sugar syrup to the sweet factory.

    Panel
    define stream SugarSyrupDataStream (temperature double, density double);

     

  2. Now let's define the output stream. To include a prediction on whether the shipment will be acceptable or not in the output, this definition must include an attribute for the prediction as shown below.

    Panel

    define stream PredictedSugarSyrupDataStream (nextTemperature double, nextDensity double, decision boolean);

  3. As you have learnt from previous tutorials, a reading from an input stream looks similar to the following.

    Panel
    from SugarSyrupDataStream

    For this scenario, you need to update it as follows.

    1. To enable the PMML extension, you need to add the #pmml:predict() annotation as shown below.

      Panel

      from SugarSyrupDataStream#pmml:predict()

    2. To access the pre-trained PMML model via which the predictions are made, specify the path as follows.

      Panel

      from SugarSyrupDataStream#pmml:predict( "/home/user/decision-tree.pmml" )

    3. Let's also add the attributes that are needed by the model for prediction.

      Panel

      from SugarSyrupDataStream#pmml:predict("/home/user/decision-tree.pmml", temperature, density)

      Based on the model definition, the output attributes can differ. Here, you have defined the model so that it can return a prediction on whether the shipment can be accepted, based on the given temperature and density.

  4. Let's route this output to the output stream as shown below.

    Panel
    from SugarSyrupDataStream#pmml:predict("/home/user/decision-tree.pmml", temperature, density)
    select *
    insert into PredictedSugarSyrupDataStream;

...

Code Block
languagesql
@App:name('SugerSyrupPredictionApp')

@source(type='http', receiver.url='http://localhost:5006/SugarSyrupEP', @map(type = 'json'))
define stream SugarSyrupDataStream (temperature double, density double);

@sink(type='log', prefix='Predicted next sugar syrup shipment:')
define stream PredictedSugarSyrupDataStream (nextTemperature double, nextDensity double, decision boolean);

from SugarSyrupDataStream#pmml:predict("/home/user/decision-tree.pmml", temperature, density)
select *
insert into PredictedSugarSyrupDataStream;