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.
12
import hana_ml
print(hana_ml.__version__)
2.20.24042601
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].
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)