Versions Compared

Key

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

Table of Contents
maxLevel3

...

There are two possible Siddhi query syntaxes to use the extension in an execution plan as follows.

  1. < double | float|long|int|string|boolean >  predict(<string> pathToMLModel, <string> dataType)
    • Extension TypeStreamProcessor
    • Description: Returns an output event with the additional attribute with the response variable name of the model, set with the predicted value, using the feature values extracted from the input event.
    • ParameterpathToMLModel:    The file path or the registry path where ML model is located. If the model storage location is registry, the value of this this parameter should have the prefix  registry:
    • Parameter: dataType: Data type of the predicted value (double, float, long, integer/int, string, boolean/bool). 

    • Example predict(‘registry:/_system/governance/mlmodels/indian-diabetes-model’)

  2. < double | float|long|int|string|boolean >  predict(<string> pathToMLModel, <string> dataType<double> input)

    • Extension TypeStreamProcessor
    • Description: Returns an output event with the additional attribute with the response variable name of the model, set with the predicted value, using the feature values extracted from the input event.
    • ParameterpathToMLModel:  The file path or the registry path where ML model is located. If the model storage location is registry, the value of this parameter should have the prefix  registry:
    • Parameter: dataType: Data type of the predicted value (double, float, long, integer/int, string, boolean/bool).

    • Parameter input:  A variable attribute value of the input stream which is sent to the ML model as feature values for predictions. Function does not accept any constant values as input parameters. You can have multiple input parameters.   

    • Example predict(‘registry:/_system/governance/mlmodels/indian-diabetes-model’, NumPregnancies, TSFT, DPF, BMI, DBP, PG2, Age, SI2)

...

  1. Download WSO2 ML, and start the server. For instructions, see Getting Started.
  2. Generate a model using WSO2 ML which you will use to make the predictions. For instructions on generating a model in WSO2 ML, see Generating Models.
  3. Download WSO2 CEP, and start the server. For instructions, see Getting Started.
  4. Download the <P2 repository> with the required features, unzip it into a local directory on your machine.

Installing required features in WSO2 CEP

Follow the steps below to install the required features in WSO2 CEP.

  1. Log in to the WSO2 CEP management console using admin/admin credentials and the following URL: https://<CEP_HOME>:<CEP_PORT>/carbon/
  2. Click Configure, and then click  Features.
  3. Click Repository Managementand then c lick Add Repository.
  4. Enter the details as shown below to add a new P2 repository. 

    Tip

    Enter the folder path of the unzipped P2 repository directory which you downloaded and saved when setting up the prerequisites, for Local of Location in the below screen.

    adding the P2 repo which has the ML featuresImage Removed

  5. Click Add.
  6. Click Available Features tab, and select the repository added in the previous step.
  7. Deselect the Group features by category option.

  8. Click Find Features. It can take a while to list out all the available features in the feature repository. Once listed, select the following features. 

    • Machine Learner Core 

    • Machine Learner Commons 

    • Machine Learner Database Service 

    • Metrics Group

    • ML Siddhi Extension

    Tip

    If you can't see this feature, retry with one of the following suggestions:

    • Try adding a more recent P2 repository. The repository you added could be deprecated.
    • Check for the feature in the Installed Features tab.

    selecting ML features to installImage Removed

  9. Once the features are selected, click Install to proceed with the installation. 

  10. Click Next, and then select I accept the terms of the license agreement.
  11. Once the installation is completed, click Restart Now, and click Yes in the message which pops up.

...

When you run WSO2 CEP in a distributed mode, the following needs to be carried out <CEP_HOME>/samples/utils/storm-dependencies.jar/pom.xml

The following dependencies should be uncommented in the <CEP_HOME>/samples/utils/storm-dependencies.jar/pom.xml file as shown below..

Code Block
languagexml
<!-- Uncomment the following depedency section if you want to include Siddhi ML extension as part of
    Storm dependencies -->

        <dependency>
            <groupId>org.wso2.carbon.ml</groupId>
            <artifactId>org.wso2.carbon.ml.siddhi.extension</artifactId>
            <version>${carbon.ml.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.ml</groupId>
            <artifactId>org.wso2.carbon.ml.core</artifactId>
            <version>${carbon.ml.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.ml</groupId>
            <artifactId>org.wso2.carbon.ml.database</artifactId>
            <version>${carbon.ml.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.ml</groupId>
            <artifactId>org.wso2.carbon.ml.commons</artifactId>
            <version>${carbon.ml.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.metrics</groupId>
            <artifactId>org.wso2.carbon.metrics.manager</artifactId>
            <version>${carbon.metrics.version}</version>
        </dependency>

        <!--&lt;!&ndash; Dependencies for Spark &ndash;&gt;-->
        <dependency>
            <groupId>org.wso2.orbit.org.apache.spark</groupId>
            <artifactId>spark-core_2.10</artifactId>
            <version>${spark.core.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.orbit.org.apache.spark</groupId>
            <artifactId>spark-sql_2.10</artifactId>
            <version>${spark.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.orbit.org.apache.spark</groupId>
            <artifactId>spark-mllib_2.10</artifactId>
            <version>${spark.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.orbit.org.apache.spark</groupId>
            <artifactId>spark-streaming_2.10</artifactId>
            <version>${spark.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.orbit.org.scalanlp</groupId>
            <artifactId>breeze_2.10</artifactId>
            <version>${breeze.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.orbit.jblas</groupId>
            <artifactId>jblas</artifactId>
            <version>${jblas.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.orbit.spire-math</groupId>
            <artifactId>spire_2.10</artifactId>
            <version>${spire.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.orbit.org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>${hadoop.client.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.uncommons.maths</groupId>
            <artifactId>uncommons-maths</artifactId>
            <version>${uncommons.maths.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.json4s</groupId>
            <artifactId>json4s-jackson_2.10</artifactId>
            <version>${json4s.jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.orbit.github.fommil.netlib</groupId>
            <artifactId>core</artifactId>
            <version>${fommil.netlib.version}</version>
        </dependency>
        <dependency>
            <groupId>org.wso2.orbit.sourceforge.f2j</groupId>
            <artifactId>arpack_combined</artifactId>
            <version>${arpack.combined.version}</version>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-csv</artifactId>
            <version>${commons.csv.version}</version>
        </dependency>
Code Block
languagexml
<!-- ML extension dependencies -->

         <include>org.wso2.orbit.org.apache.spark:spark-core_2.10
         </include>
         <include>org.wso2.orbit.org.apache.spark:spark-sql_2.10
         </include>
         <include>org.wso2.orbit.org.apache.spark:spark-mllib_2.10
         </include>
         <include>org.wso2.orbit.org.apache.spark:spark-streaming_2.10
         </include>
         <include>org.wso2.orbit.org.scalanlp:breeze_2.10</include>
         <include>org.wso2.orbit.jblas:jblas</include>
         <include>org.wso2.orbit.spire-math:spire_2.10</include>
         <include>org.wso2.orbit.org.apache.hadoop:hadoop-client
         </include>
         <include>org.wso2.uncommons.maths:uncommons-maths</include>
         <include>org.wso2.json4s:json4s-jackson_2.10</include>
         <include>org.slf4j:slf4j-api</include>
         <include>org.wso2.orbit.github.fommil.netlib:core</include>
         <include>org.wso2.orbit.sourceforge.f2j:arpack_combined
         </include>
         <include>org.scala-lang:scala-library</include>
         <include>org.apache.commons:commons-csv</include>
         <include>org.wso2.carbon.ml:org.wso2.carbon.ml.core</include>
         <include>org.wso2.carbon.ml:org.wso2.carbon.ml.database
         </include>
         <include>org.wso2.carbon.ml:org.wso2.carbon.ml.commons</include>
         <include>
             org.wso2.carbon.ml:org.wso2.carbon.ml.siddhi.extension
         </include>
         <include>
             org.wso2.carbon.metrics:org.wso2.carbon.metrics.manager
         </include>

...

Create a directory named patchxxxx in the <CEP_HOME>/repository/components/patches.

Tip

Replace xxxx with a number that is greater by 1 than the number of the latest patch directory.

...

Installing required features in WSO2 CEP

  1. Install the WSO2 Machine Learner (ML) Features. For detailed instructions to install WSO2 ML features, see Installing Machine Learner Features.

Creating the input stream

Follow the steps below to create the input stream in WSO2 CEP.

  1. Log in to the CEP management console using the following URL, if you are not already logged in:  https://<CEP_HOME>:9443/carbon/
  2. Click  Main, and then click Event Streams in the Event Processor menu.
  3. Click  Add Event Stream .
  4. Enter details of the stream definition that you want to create as shown below.
    add input event streamImage Removed Image Added
  5. Click  Add Event Stream ,   to create the event stream in the system.  You view the new  input stream added to the list of all available event streams as shown below .
    event streams listImage Removed Image Added

Creating the output stream

...

  1. Log in to the CEP management console using the following URL, if you are not already logged in: https://<CEP_HOME>:<CEP_PORT>/carbon/
  2. Click Main, and then click Event Streams in the Event Processor menu.
  3. Click Add Event Stream.
  4. Enter details of the stream definition that you want to create as shown below.
    Image Removed Image Added
  5. Click Add Event Stream, to create the event stream in the system. You view the new output stream added to the list of all available event streams as shown below .
    output stream in event streams listImage Removed Image Added

Creating the execution plan

...

  1. Log in to the CEP management console using the following URL, if you are not already logged in: https://<CEP_HOME>:<CEP_PORT>/carbon/
  2. Click Main, and then click Execution Plans in the Streaming Analytics menu.
  3. Click Add Execution Plan.
  4. Select InputStream:1.0.0 for Import Stream from the list, and click Import.
  5. Enter the name of the output stream (PredictionStream) for Value Of, select PredictionStream:1.0.0 from the Stream ID list, and click Export for Export Stream.

  6. Enter the following Siddhi query as shown below.

    Tip

    Replace your file or registry path where to locate the downloaded ML model as the first argument and the response variable data-type as the second variable of the predict() function in the below execution plan as described in Siddhi syntax for the extension .

    Code Block
    languagesql
    from InputStream#ml:predict('registry:/_system/governance/ml/indian-diabetes-model', 'double')
    select *
    insert into PredictionStream;

    Image RemovedImage Added

    Click Validate Query Expressions, to validate the query you entered.

  7. Click Add Execution Plan to save the execution plan in the system. You view the execution plan added to the list of all available execution plans as shown below.
    execution plans listImage Removed Image Added

Creating an event publisher

...

  1. Log in to the CEP management console using the following URL, if you are not already logged in: https://<CEP_HOME>:<CEP_PORT>/carbon/
  2. Click Main, and then click Execution Plans in the Event menu.
  3. Click Add Event Publisher.
  4. Enter the details as shown below to create a logger type event publisher.
    Image Removed Image Added
  5. Click Add Event Publisher, to create the event publisher in the system. You view the new event publisher added to the list of available event publishers. 
  6. Click the corresponding Enable Tracing button as shown below.
    enable event tracingImage Removed Image Added

Simulating events

...

  1. Log in to the CEP management console using the following URL, if you are not already logged in: https://<CEP_HOME>:<CEP_PORT>/carbon/
  2. Click Tools, and then click Event Simulator.
  3. Select InputStream:1.0.0 for the Event Stream Name.
  4. Enter the feature values to predict, in the Stream Attributes input fields as shown below.
    Image Removed Image Added

  5. Click Send, to send the events. You view the values of the output stream named  PredictionStream logged by the event publisher in the back end console logs of WSO2 CEP as shown below.

    Image RemovedImage Added