Community Articles

Find and share helpful community-sourced technical articles.
avatar
Contributor

Introduction:

This article is designed to get the reader to call a deployed CML model from Apache NiFi or Cloudera Data Flow as quickly as possible.  It will require using one of Cloudera's Applied Machine Learning Prototypes (AMPs) on Customer Churn and the Apache NiFi Flow provided in this article.  (Git Repo Here)

Prerequisites:

  1. Apache NiFi instance is running.
  2. CML's AMP Customer Churn App is running with a Churn Model deployed. 
  3. Download the user data file and Apache Nifi flow from this repo
  4. The user data file needs to be added to the file location where NiFi's GetFile Processor has permissions. 

Launch CML Churn AMP

Screen Shot 2023-08-02 at 10.08.31 AM.png

In the AMP catalog, select Churn Modeling with skit-learn, and configure a new project.  This will take 5-7 minutes to complete.  You will need to deploy a model inside of CML, which isn't in the scope of this article.  Once you finish, you will be able to see the following screen, which will provide the URL location and API key for the model. 

Screen Shot 2023-08-02 at 10.13.19 AM.png

NiFi Flow Overview:

This article will include a single customer file in JSON and an Apache NiFi Data flow, which will need to be configured to call the model deployed in CML. The following screenshot displays the template once it has been added to the working canvas. 
Screen Shot 2023-08-02 at 9.32.21 AM.png

Processor Configuration:

GetFile Processor

Screen Shot 2023-08-02 at 9.27.40 AM.png

In the GetFile processor, the input directory needs to contain the customer JSON file that is included with the article.   

EvaluateJSON Processor 

Screen Shot 2023-08-02 at 9.27.59 AM.png

The included Data Flow file has this processor configured, but this step is essential to appreciate.  This processor will take values from the JSON file and add them as attribute values. Once these values are an attribute, they can be used to call the model in the next step. 

InvokeHTTP Processor

Screen Shot 2023-08-02 at 9.28.44 AM.png
You will need to add the URL location of the model deployed in CML, which is pictured above. You will also need to include the API key with the model call in the image below:
Screen Shot 2023-08-02 at 9.28.23 AM.png

Successful Results

Once the processors have been configured, the model can be called the results can be displayed by opening the queue and selecting the response value.

Screen Shot 2023-08-02 at 10.25.50 AM.png
 
Here is an example of deployed model's response. 
Screen Shot 2023-08-01 at 4.51.13 PM.png

2,087 Views
Comments

@ibrooks Excellent article here.  I will definitely be using this in my CML Demos going foward.   I just sent a PR w/ some flow improvements you may like to use as well.