Digital Developer Conference: Cloud Security 2021 -- Build the skills to secure your cloud and data Register free

Build streams flow to analyze and predict realtime data


There is no product that appeals to all potential customers. How are those offering products to know which potential customer is likely to purchase the product? In this pattern, we gather a customer-related dataset and, based on that, predict whether the customer will buy the product if offered. All of this will happen in real-time on a dashboard so that it helps the retailer to better understand which type of customers to target to get the maximum sales of their product.


We take the use case of a bank selling the personal loan to its customers and predict whether the customer will accept a loan offered to them or not. We will code the machine learning model in a Jupyter notebook in Watson Studio and deploy the model to Watson Machine Learning. Further, we design a streams flow in Watson Studio that has an input node which brings in the data from various sources such as REST API calls, stream events from a Kafka broker, IBM® Cloud Event Streams, MQTT broker, Watson IoT™ device platform etc… which is streamed as input to the next node that is the python model invoked from Watson Machine Learning. The predictions and various features affecting the prediction are reviewed as output which is then stored in IBM Cloud Object Storage as a csv file. A streaming analytics instance associated with the flow will start running as soon as the flow is deployed and live data and predictions can be monitored on the IBM Streaming Analytics dashboard in real-time.



  1. Create a REST API with Python and deploy it to Cloud Foundry service. Calling this API returns a json with random attribute values of the outsource dataset. Thus it simulates real-time data.
  2. Create a Watson Studio instance and a Watson Machine Learning instance in IBM Cloud.
  3. Create a new Jupyter notebook in Watson Studio and execute the cells to successfully train, test, get accuracy and deploy the model to Watson Machine Learning.
  4. Once the real-time data source and the machine learning model is ready the stream flow can be built. Create a new streams flow in Watson Studio.
  5. Build a flow with input as the REST API, data processing by the deployed Watson Machine Learning model and save the output to a csv file in Cloud Object Storage.
  6. Launch the Streaming Analytics dashboard and visualize the data in real-time.


Find the detailed steps for this pattern in the readme file. The steps will show you how to:

  1. Clone the repo
  2. Deploy API
  3. Create Watson Services
  4. Run the Jupyter Notebook and Deploy the ML Model
  5. Create IBM Streaming Analytics service
  6. Create the Streams Flow in Watson Studio
  7. Visualize the Streams Dashboard