Skip to Content

Export Python ML model to HANA for productive use


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.


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



Add comment
10|10000 characters needed characters exceeded

  • Follow
  • 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

    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_ ='ROW_INDEX', 'MODEL_CONTENT')

    Models that use the Automated Predictive Library (APL4) already have save_model() and load_model() methods.

    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