SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Ingest Live Data into your House Price Predictor with SAP AI Core

Build data pipelines and reuse code to train and generate models on different datasets.

Overview

🎓 beginner 45 min. SAP Ai CoreBeginnerArtificial IntelligenceMachine LearningSAP Ai Launchpad

You will learn

  • โœ”How to create placeholders for datasets in your code and associated AI workflow.
  • โœ”How to register datasets stored in AWS S3 to SAP AI Core.
  • โœ”How to use datasets with placeholders.
  • โœ”How to generate models and store them in AWS S3 for later use.

Prerequisites

Prerequisites

  • A BTP global account If you are an SAP Developer or SAP employee, please refer to the following links ( for internal SAP stakeholders only ) - How to create a BTP Account (internal) SAP AI Core If you are an external developer or a customer or a partner kindly refer to this tutorial
  • You have knowledge on connecting code to AI workflows of SAP AI Core.
  • You have created your first pipeline with SAP AI Core, using this tutorial.

Steps

Intro

By the end of the tutorial you will have two models trained on two different datasets of house price data. It is possible to change the names of components and file paths mentioned in this tutorial, without breaking the functionality, unless stated explicitly.

IMPORTANT Before you start this tutorial with SAP AI Launchpad, it is recommended that you set up at least one other tool, either Postman or Python (SAP AI Core SDK) because some steps of this tutorial cannot be performed with SAP AI Launchpad.

Please Note : In order to execute this tutorial you have to upgrade to Standard Plan from Free Tier of AI Core.

If you have run the first two tutorials

1.Quick Start Your first AI project using SAP AI Core

2.Build a house Price predictor with SAP AI Core

Using SAP AI Core Free Tier then you have fulfilled all your quota for execution with the free tier. If you have run the execution once then you cannot run any more executions.

As the Tutorials will need you to run multiple executions, hence you need to upgrade your AI Core Plan from free tier to Standard as shown in the successive steps in the tutorial.

Please find downloadable sample notebooks for the tutorials : . Note that these tutorials are for demonstration purposes only and should not be used in production environments. To execute them properly, you’ll need to set up your own S3 bucket or provision services from BTP, including an AI Core with a standard plan for narrow AI and an extended plan for GenAI HUB. Ensure you input the service keys of these services into the relevant cells of the notebook. Link to notebook


Step 1 Modify AI code
โ€”

Create a new directory named hello-aicore-data. The code is different from previous tutorial as it reads the data from folder (volumes, virtual storage spaces). The content of these volumes is dynamically loaded during execution of workflows.

Create a file named main.py, and paste the following snippet there:

Python
import os
#
# Variables
DATA_PATH = '/app/data/train.csv'
DT_MAX_DEPTH= int(os.getenv('DT_MAX_DEPTH'))
MODEL_PATH = '/app/model/model.pkl'
#
# Load Datasets
import pandas as pd
df = pd.read_csv(DATA_PATH)
X = df.drop('target', axis=1)
y = df['target']
#
# Partition into Train and test dataset
from sklearn.model_selection import train_test_split
train_x, test_x, train_y, test_y = train_test_split(X, y, test_size=0.3)
#
# Init model
from sklearn.tree import DecisionTreeRegressor
clf = DecisionTreeRegressor(max_depth=DT_MAX_DEPTH)
#
# Train model
clf.fit(train_x, train_y)
#
# Test model
test_r2_score = clf.score(test_x, test_y)
# Output will be available in logs of SAP AI Core.
# Not the ideal way of storing /reporting metrics in SAP AI Core, but that is not the focus this tutorial
print(f"Test Data Score {test_r2_score}")
#
# Save model
import pickle
pickle.dump(clf, open(MODEL_PATH, 'wb'))
Step 2 Understanding your code
+
Step 3 Create placeholders for datasets in workflows
+
Step 4 Understanding changes in your workflow
+
Step 5 Create placeholders for hyperparameters
+
Step 6 Set resource plan
+
Step 7 Observe your scenario and placeholder
+
Step 8 Create cloud storage for datasets and models
+
Step 9 Connect local system to AWS S3
+
Step 10 Upload datasets to AWS S3
+
Step 11 Store an object store secret in SAP AI Core
+
Step 12 Create artifact to specify folder of dataset
+
Step 13 Locate artifacts
+
Step 14 Use artifacts with workflows using a configuration
+
Step 15 Run you workflow using execution
+
Step 16 Set model pipeline in workflow
+
Step 17 Description of changes
+
Step 18 Create required object store secret `default` for model
+
Step 19 Create another configuration with new data
+
Step 20 Create another execution
+
Step 21 Schedule your execution (Optional)
+
Step 22 Locate your model in AWS S3
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 22
1. Modify AI code 2. Understanding your code 3. Create placeholders for datasets in workflows 4. Understanding changes in your workflow 5. Create placeholders for hyperparameters 6. Set resource plan 7. Observe your scenario and placeholder 8. Create cloud storage for datasets and models 9. Connect local system to AWS S3 10. Upload datasets to AWS S3 11. Store an object store secret in SAP AI Core 12. Create artifact to specify folder of dataset 13. Locate artifacts 14. Use artifacts with workflows using a configuration 15. Run you workflow using execution 16. Set model pipeline in workflow 17. Description of changes 18. Create required object store secret `default` for model 19. Create another configuration with new data 20. Create another execution 21. Schedule your execution (Optional) 22. Locate your model in AWS S3

Learn more →