cancel
Showing results for 
Search instead for 
Did you mean: 

Export Python ML model to HANA for productive use

0 Kudos

Hi,

scenario description:

in the Jupyter notebook I have implemented the model with python. The training data is stored on the HANA database and I used the Python API to create the model in the Jupyter notebook - this all worked fine.

Question:

Now that I have a good model I want to export it to HANA and use it there for productive use. How can I export it to HANA and automate the process for doing the predictions there? Is it good to do with AMDP classes or are there better approaches for productive use?

System environmend:

  • HANA 2, SP03
  • Python 3.7.3
  • hana_ml 1.0.5

BR

Robert

Accepted Solutions (1)

Accepted Solutions (1)

AndreasForster
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Robert, A PAL model can be saved to a HANA table but the feature might be undocumented at the moment. So it might change, etc... Please use with caution. This code saves a model of type trees.DecisionTreeRegressor
model = tree_reg.model_.select('ROW_INDEX', 'MODEL_CONTENT')
model.save(("ML", "USEDCARPRICES_MODEL_REGTREE"))

It can then be loaded from the table with
import hana_ml as hana_ml
from hana_ml.algorithms.pal import trees
df_model_saved = hana_ml.dataframe.DataFrame(conn, 'select * from ML.USEDCARPRICES_MODEL_REGTREE')
tree_reg_saved = trees.DecisionTreeRegressor(conn, algorithm='cart')
tree_reg_saved.model_ = df_model_saved.select('ROW_INDEX', 'MODEL_CONTENT')

Models that use the Automated Predictive Library (APL4) already have save_model() and load_model() methods. https://help.sap.com/doc/0172e3957b5946da85d3fde85ee8f33d/latest/en-US/html/hana_ml.algorithms.apl.h...

To have PAL or APL models retrained and applied automatically I suggest looking at SAP Data Intelligence (SAP DI = Data Hub + ML in the cloud). You can deploy the Python syntax there as Python operator in a graph. I believe you could use that SAP Data Intelligence also to expose the trained model as REST API web service.

Many Greetings, Andreas

0 Kudos

Thanks Andreas, your above coding for saving/loading the ML model works great. I will make my mind about deploying with SAP DI

BR

Robert

Answers (0)