Skip to Content

Export Python ML model to HANA for productive use

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    May 13 at 10:07 AM

    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.html

    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

    Add comment
    10|10000 characters needed characters exceeded