Nyoka - yet another snake in the Python Zoo
Tags: nyoka, python, zementis
Published: 2019-09-12 11:22:04

---
title: Nyoka - yet another snake in the Python Zoo
published: true
tags: #nyoka, #python, #zementis
canonical_url: http://techcommunity.softwareag.com/techniques-blog/-/blogs/nyoka-yet-another-snake-in-the-python-zoo
---

# Support for data science with Python

**In this article we introduce Nyoka, a new Python-based library that exports predictive models from popular machine learning/deep learning frameworks to PMML. Using Nyoka, data scientists can standardize and accelerate the deployment process for predictive models.**

_By Alexander Lemm, Sr. Product Manager, Predictive Analytics, Software AG and Dr. Rainer Burkhardt, Sr. Director, AI Analytics, Software AG_

| Issue 4, 2018 | [<font color="#000000"><img alt="" id="yui_patched_v3_11_0_1_1435667347988_855" src="http://techcommunity.softwareag.com/image/image_gallery?uuid=202eb7e1-9148-4c65-b29a-54c4302ab65e&amp;groupId=10157&amp;t=1326987658425" style="width: 22px; height: 22px; vertical-align: text-bottom;"> <span id="yui_patched_v3_11_0_1_1492771711676_1198">Download PDF</span> </font>](http://techcommunity.softwareag.com/ecosystem/download/techniques/2018-issue4/SAG_Nyoka_Release_TECHniques_Oct18_WEB.pdf) |
|-|-|-|
## Introduction

In August, Software AG released Nyoka on GitHub®, a Python library for data scientists. But what is Nyoka exactly and what does it stand for? Using Nyoka, a data scientist can export predictive models created with popular Python-based machine learning or deep learning frameworks into PMML (see figure 1 below). "Nyoka" originates from Zulu and means "snake," hence the close connection to its Python cousin.

![](http://techcommunity.softwareag.com/documents/10157/10000089/nyoka1.png/13783207-d3f2-4c93-bd72-2a66d11ff45b?t=1539765499003)  
**Fig 1:** Supported Machine Learning and Deep Learning Frameworks

PMML is an XML-based predictive model interchange format and the leading standard for statistical and machine learning models. The Data Mining Group (DMG) is an independent, vendor-led consortium that supports and drives the development of PMML for nearly 20 years now.

Nyoka underscores Software AG's Artificial Intelligence (AI) strategy and vision of open industry standards: PMML as the unifying standard for machine learning AND deep learning models.

## Nyoka in action

Let us check out a simple example on how you can use Nyoka to export a pre-trained MobileNet model for image recognition from Keras to PMML. Here we assume that you already loaded all necessary libraries into memory.

```
# load pretrained keras mobilenet model model = mobilenet.MobileNet(input\_shape=(224, 224, 3), alpha=1.0, depth\_multiplier=1,                             dropout=1e-3, include\_top=True, weights='imagenet',                             input\_tensor=None, pooling=None, classes=1000)   # convert mobilnet model to PMML cnn\_pmml = KerasToPmml(model, model\_name="KerasMobileNet", dataSet="ImageNet")   # Save mobilenet PMML to disk cnn\_pmml.export(open("mobilenet\_demo.pmml, "w"),0)
```

Constructing an object named cnn\_pmml as an instance of the Nyoka class KerasToPMML() is all you need to do to convert the MobileNet model into its PMML representation. Saving it to disk is done by calling the method export().

But what is a PMML file good for when you don't leverage it for predicting new and unseen values – which are in our case unclassified images?

To do just this, we use one execution engine for PMML files, the Zementis Server, Software AG's flagship product in the AI domain. Therefore, deploying the created PMML file from the example above to a Zementis Server instance is next. We assume again that you already loaded all necessary libraries into memory.

```
pmml\_file = open(mobilenet\_demo.pmml,"r") pmml = {'file': pmml\_file} pmml\_upload = requests.post(adapaRS + "model/", files=pmml, auth=auth, verify=False,                             params = {"applyCleanser": "FALSE"})
```

The model is now deployed to a Zementis Server instance and can be executed to classify any unseen image. We will send the following picture to the server showing a great white shark.

![](http://techcommunity.softwareag.com/documents/10157/10000089/nyoka2.jpg/fc1e5eb3-db5a-40a8-8c23-aa86a98ea642?t=1539765502577)  
**Fig 2:**  Image we are going to Classify

```
f = open("shark\_224\_224.png", "rb") files ={'file':f.read()} resp = requests.post(adapaRS+'apply/KerasMobileNet' , auth=auth, files=files,headers={},verify=False)
```

Curious what the classification result from the Zementis Server is? Let's check it out!

```
Print(resp.text) { "model" : "KerasMobileNet", "outputs" : [{ "top1\_prob" : 0.9951145648956299, "predictedValue\_predictions" : "great\_white\_shark", "top5\_prob" : "great\_white\_shark:0.9951145648956299,tiger\_shark:0.0029412976000458,sturgeon:0.0012288052821531892,dugong:3.0053118825890124E-4,killer\_whale:2.2845140483696014E-4" }] }
```

As you can see, the deployed MobileNet model classifies the image as a great white shark with an probability of 99.5%.  
Examining the output you see that Zementis Server not just gives you the best classification result and the respective probability but in fact the five best results.

## Conclusion

In this article we just scratched the surface of Nyoka's capabilities. With Nyoka you can even create your own exporters for specialized/individual model types.

You would like to learn more about Nyoka and make a deep dive yourself? Please check out the following links:

- Nyoka is available on [GitHub including Docs](https://github.com/nyoka-pmml/nyoka) and comes with Jupyter notebook based tutorials. And if you have feedback and questions about Nyoka - just open a [GitHub issue](https://github.com/nyoka-pmml/nyoka/issues) and we'll get back to you!
- If you would like to go one step further and put your generated PMML files into action, get a [free trial license for Zementis Server](https://aws.amazon.com/marketplace/pp/B07FRBG344), our PMML execution engine.

 

[Learn more about Zementis and download your free trial today.](https://www.softwareag.com/corporate/products/apama_webmethods/zementis/default)