Configuring the Python Machine Learning Client for SAP HANA

Objectives

After completing this lesson, you will be able to:
  • Install the hana-ml package and establish a connection to SAP HANA Cloud.
  • Establish a reliable connection context for your machine learning tasks.

Technical Prerequisites

To effectively work with classification models in SAP HANA, you will need the following prerequisites:

  • Instance of SAP HANA Cloud with ScriptServer (APL, PAL enabled)
  • Python hana-ml package 2.21.24062800, other packages and dependencies installed
  • Basic Structured Query Language (SQL) knowledge is highly desirable

Setting up and Preparing the Environment

Before implementing classification models in SAP HANA, it is essential to set up the required environment. This includes installing the necessary Python libraries, establishing a connection to SAP HANA Cloud, and configuring authentication settings to ensure seamless integration and secure access to machine learning functions.

The following cell loads/imports diverse modules needed for the current Demo. As you may know a module can be considered to be the same as a code library.

Code Snippet
12
import hana_ml print(hana_ml.__version__)

2.20.24042601

Code Snippet
12345678910111213
#importing other packages used import pandas as pd import matplotlib.pyplot as plt import time import numpy as np import os import time import json from hana_ml.visualizers.unified_report import UnifiedReport from hana_ml.algorithms.pal.unified_classification import UnifiedClassification from hana_ml.algorithms.pal.partition import train_test_val_split %matplotlib inline

SAP HANA Cloud Database Connection

In the Python machine learning client for SAP HANA (hana-ml), all connections are linked to a HANA DataFrame. Additionally, when working with SAP HANA Cloud, an encrypted connection is required for security.

To establish a connection, learners must have the SAP HANA system address and valid credentials. These details are essential for instantiating the hana_ml.dataframe.ConnectionContext class, which represents a connection to an SAP HANA database instance [1].

Code Snippet
1234567891011
from hana_ml import dataframe address = "b8xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.hana.prod-eu10.hanacloud.ondemand.com" port = 443 user = 'ML_DEMO' conn = dataframe.ConnectionContext(address, port, user, encrypt=True, sslValidateCertificate=False) # Control connection print(conn.connection.isconnected()) print(conn.hana_version())

True

4.00.000.00.1720524034 (fa/CE2024.14)

Log in to track your progress & complete quizzes