Slide 1

Slide 1 text

Hands-On Lab: Introduction to Oracle Machine Learning for Python on Autonomous Database Learn about Oracle Machine Learning for Python (OML4Py) including AutoML and RESTful interfaces with data- and task-parallelism. Marcos Arancibia Presenter, Product Manager, Oracle Machine Learning Mark Hornick, Sherry LaMonica Oracle Machine Learning product team

Slide 2

Slide 2 text

Agenda • Introduction to the team • Objectives of this LiveLab workshop • About the Lab contents • Provision an Autonomous Database and start working on the Labs • Wrap up and next Tasks 2 Copyright © 2022, Oracle and/or its affiliates

Slide 3

Slide 3 text

Roles & Names 3 Copyright © 2022, Oracle and/or its affiliates Marcos Presenter Mark Q&A Sherry Technical Support

Slide 4

Slide 4 text

Objectives of this LiveLab 4 Copyright © 2022, Oracle and/or its affiliates

Slide 5

Slide 5 text

• Test drive the new Oracle Machine Learning for Python available with Oracle Autonomous Database • Explore different aspects of in-database machine learning through a Python API using OML Notebooks • Interactively work with your data, and build, evaluate, and apply machine learning models, including new AutoML • Do some “Try if yourself” exercises to check your understanding Objectives Copyright © 2022, Oracle and/or its affiliates 5

Slide 6

Slide 6 text

The main goal of this 120-minute Hands-on-Lab Session is to get you familiar with the OML4Py Live Labs, become self-sufficient with the environment, and show many of the OML4Py capabilities These labs focus on the Python API only. Please note that there is also a REST API available for embedded Python execution on ADB, but will not be covered This series of labs is not intended as an introduction to machine learning or details of specific algorithms To learn more about Machine Learning concepts, check out the recorded OML Office Hours ML 101/102 sessions starting in May of 2020 at https://bit.ly/omlasktom Setting expectations Copyright © 2022, Oracle and/or its affiliates 6

Slide 7

Slide 7 text

Lab Overview • Lab 0 - Provision an Autonomous Data Warehouse with OML users • Lab 1 - Getting Started with OML4Py • Lab 1a – OML4Py table creation and grants • Lab 2 - Select and manipulate data using the Transparency Layer • Lab 3 - Use in-database algorithms and models • Lab 4 - Store and manage Python objects and user-defined functions • Lab 5 - Run user-defined functions using Embedded Python Execution • Lab 6 - Use AutoML • Bonus Lab – Use AutoML UI Need access later or want to forward to your friends? • This workshop is available 365 days a week 24/7 7 Copyright © 2022, Oracle and/or its affiliates

Slide 8

Slide 8 text

Have questions? Need lab help? Questions about Oracle Machine Learning and/or OML4Py? Technical problems with a Free Tier setup or with your own Autonomous Database instance? Please message us in the Q&A section in Zoom, and we will help you Please let us know if you have any problems at anytime. There are experts available to talk to you 1:1 if needed

Slide 9

Slide 9 text

9 Copyright © 2022, Oracle and/or its affiliates Free Tier or Run on your own Tenancy Instructions Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 10

Slide 10 text

Accessing the lab 1. Open a web browser (Chrome/Firefox preferred) 2. Enter the bit.ly link below bit.ly/oml4pyhol …or use the QR 10 Copyright © 2022, Oracle and/or its affiliates Click on either "Launch Free Trial" or "Run on your own Tenancy" if you have one available

Slide 11

Slide 11 text

12 Copyright © 2022, Oracle and/or its affiliates Lab 0: Provision an Autonomous Data Warehouse with OML users Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 12

Slide 12 text

Copyright © 2022, Oracle and/or its affiliates 13 Technical problems? Questions about Oracle Machine Learning or OML4Py? Message us in Q&A at anytime ! Click on Lab 0 We will follow the Instructions on this section

Slide 13

Slide 13 text

14 Copyright © 2022, Oracle and/or its affiliates In another Browser tab or window, log into your Oracle Cloud instance Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 14

Slide 14 text

Copyright © 2022, Oracle and/or its affiliates 15 Technical problems? Questions about Oracle Machine Learning or OML4Py? Message us in Q&A at anytime ! If you do not have an Oracle Cloud account yet, register for free at https://oracle.com/cloud/free Click on "Start for Free" and then fill in the Account Information page

Slide 15

Slide 15 text

Copyright © 2022, Oracle and/or its affiliates 16 Technical problems? Questions about Oracle Machine Learning or OML4Py? Message us in Q&A at anytime ! When you sign up for an Oracle Cloud account, a user is created for you in Oracle Identity Cloud Service with the username and password you selected at sign up. You can use this single sign-on option to sign into Oracle Cloud Infrastructure and then navigate to other Oracle Cloud services without re-authenticating. This user has administrator privileges for all the Oracle Cloud services included with your account. Open the e-mail you received when you signed up or go to https://cloud.oracle.com to login into your Cloud account.

Slide 16

Slide 16 text

Copyright © 2022, Oracle and/or its affiliates 17 Technical problems? Questions about Oracle Machine Learning or OML4Py? Message us in Q&A at anytime ! Oracle Cloud Infrastructure Home page

Slide 17

Slide 17 text

To create a Compartment Copyright © 2022, Oracle and/or its affiliates 20 Technical problems? Questions about Oracle Machine Learning or OML4Py? Message us in Q&A at anytime ! 1. Click on the "hamburger" menu (top left) 2. Click on "Identity & Security" 3. Click on "Compartments"

Slide 18

Slide 18 text

Copyright © 2022, Oracle and/or its affiliates 21 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Click on the button "Create Compartment" Give it a name, a description and use the (root) as the Parent. Click "Create Compartment

Slide 19

Slide 19 text

22 Copyright © 2022, Oracle and/or its affiliates Creating an Autonomous Database Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 20

Slide 20 text

Copyright © 2022, Oracle and/or its affiliates 23 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature 1. Click on the "hamburger" menu (top left) 2. Click on "Autonomous Database" under Featured

Slide 21

Slide 21 text

Copyright © 2022, Oracle and/or its affiliates 24 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature 1. Select the Compartment that you just created 2. Click "Create Autonomous Database" 3. Enter "OML LABS" as display name, and "OMLLABS" (no spaces) as Database name

Slide 22

Slide 22 text

Copyright © 2022, Oracle and/or its affiliates 25 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature 1. Use the default of Data Warehouse, on Shared infrastructure 2. Check the Always Free with 19c Release 3. If you have problems configuring an Always Free instance, go with 1 OCPU with Auto Scaling, default Storage and 19c Release

Slide 23

Slide 23 text

Copyright © 2022, Oracle and/or its affiliates 26 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Your new Autonomous Database instance is being provisioned Password must be 12 to 30 characters and contain at least one uppercase letter, one lowercase letter, and one number. The password cannot contain the double quote (") character or the username "admin". Use defaults

Slide 24

Slide 24 text

29 Copyright © 2022, Oracle and/or its affiliates Introduction to OML4Py Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 25

Slide 25 text

Copyright © 2022, Oracle and/or its affiliates 30 Oracle Machine Learning OML Services OML4SQL OML4Py OML4R OML Notebooks OML4Spark Oracle Data Miner OML AutoML UI Interfaces for 3 popular data science languages: SQL, R, and Python Collaborative notebook environment based on Apache Zeppelin with Autonomous Database SQL Developer extension to create, schedule, and deploy ML solutions through a drag-and-drop interface ML for the big data environment from R with scalable algorithms No-code AutoML interface on Autonomous Database Model Deployment and Management, Cognitive Text

Slide 26

Slide 26 text

Copyright © 2022, Oracle and/or its affiliates 31 Oracle Machine Learning Increase productivity, Achieve enterprise goals, Innovate more Automated Get better results faster with less effort – even non-expert users Scalable Handle big data volumes using parallel, distributed algorithms – no data movement Deployable Deploy and update data science solutions faster with production-ready and integrated ML platform Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 27

Slide 27 text

Oracle Machine Learning for Python Use Oracle Database as HPC environment • Explore, transform, and analyze data faster and at scale Use in-database parallelized and distributed ML algorithms • Build more models on more data, and score large volume data – faster • Use in-database algorithms from OML4SQL via well-integrated Python API • Increased productivity from automatic data preparation, partitioned models, and integrated text mining capabilities Run user-defined Python functions in database-spawned and controlled Python engines and manage Python objects in-database • Collaborate: hand-off data science products from data scientist to developers easily • Run user-defined functions in data-parallel, task-parallel, and non-parallel fashion • Return structured and image results in Python and REST API Automated machine learning (AutoML) and model explainability (MLX) • Enhance data scientist productivity and enable non-experts to use and benefit from machine learning • Algorithm selection, feature selection, hyperparameter tuning, model selection • Model-agnostic identification of important features that impact model predictions Empower data scientists with Python for in-database machine learning Copyright © 2022, Oracle and/or its affiliates 32 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature OML4Py REST Interface Oracle Autonomous Database Oracle Database SQL Interface

Slide 28

Slide 28 text

33 Copyright © 2022, Oracle and/or its affiliates Accessing Autonomous Database Actions to create ML users Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 29

Slide 29 text

Copyright © 2022, Oracle and/or its affiliates 35 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Your new Autonomous Database instance is Available now (the ADW fill changes to green). Let's Launch the Database Actions

Slide 30

Slide 30 text

Copyright © 2022, Oracle and/or its affiliates 36 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Click on the SQL tile

Slide 31

Slide 31 text

Copyright © 2022, Oracle and/or its affiliates 37 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Back in the workshop, on Lab 0, Task 5, click on the "Copy" button to copy the necessary code to the buffer

Slide 32

Slide 32 text

Copyright © 2022, Oracle and/or its affiliates 38 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature 1. Paste the code into the empty SQL worksheet. 2. Run the entire script by pressing F5 or clicking the "Run Script" button 3. These messages will indicate success!

Slide 33

Slide 33 text

39 Copyright © 2022, Oracle and/or its affiliates Lab 1: Getting Started with OML4Py Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 34

Slide 34 text

Copyright © 2022, Oracle and/or its affiliates 41 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature 1. In the Autonomous Database console, click on the "Service Console" button 2. Click on "Development" 3. Then click on the Oracle Machine Learning User Interface tile

Slide 35

Slide 35 text

1. Sign in with OMLUSER, and the password: AAbbcc123456 Copyright © 2022, Oracle and/or its affiliates 42 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature 2. Click on "Notebooks" from the Quick Actions menu

Slide 36

Slide 36 text

Copyright © 2022, Oracle and/or its affiliates 43 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Make sure to click the link shown in the Lab 1, Task 2, and download the ZIP file containing the notebooks for the Labs to your local machine. Please UNZIP/Extract the files to a folder you will remember. To IMPORT the notebooks, click on IMPORT and then search for the JSON files that were extracted. You can import them all at once.

Slide 37

Slide 37 text

Copyright © 2022, Oracle and/or its affiliates 44 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature 1. Click on Lab 1 to open it 2. Once inside Lab 1, click on the top right gear icon to check the Interpreter Bindings 3. Drag the xxxx_medium interpreter up. Optionally click on the low and high ones to disable them (they become white). Then click on Save.

Slide 38

Slide 38 text

Copyright (c) 2022 Oracle Corporation Copyright © 2022, Oracle and/or its affiliates 45 Run All Show/Hide Code Show/Hide Output Clear Output Clear Notebook Export Notebook Search Code Connected Users List Shortcuts Interpreter Bindings Paragraph Status Show Editor Run Paragraph Hide Output More Features Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Overview of the different buttons available in Oracle Machine Learning Notebooks interface

Slide 39

Slide 39 text

46 Copyright © 2022, Oracle and/or its affiliates Notebook "Lab 1a: Run Me First - OML4Py table creation and grants" Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 40

Slide 40 text

Copyright © 2022, Oracle and/or its affiliates 47 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Let's switch to the notebook for Lab 1a, by going back to the main Notebooks listing and clicking on Lab 1a.

Slide 41

Slide 41 text

Copyright © 2022, Oracle and/or its affiliates 48 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature VERIFY THAT IT RAN SUCCESSFULLY: Scroll down to last paragraph and check for: The phrase "PL/SQL procedure successfully completed" The current date and time as "Last Updated" Copyright (c) 2022 Oracle Corporation IMPORTANT: We need to check the Interpreters before running all paragraphs. We need to run them all at this point, to generate the dataset needed in most Labs from 2 to 6.

Slide 42

Slide 42 text

49 Copyright © 2022, Oracle and/or its affiliates Lab 2: Select and manipulate data using the transparency layer Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 43

Slide 43 text

Transparency Layer Leverages proxy objects for database data: oml.DataFrame # Create table from Pandas DataFrame df DATA = oml.create(df, table = 'BOSTON') # Get proxy object to DB table boston DATA = oml.sync(table = 'BOSTON') or DATA = oml.sync(query = 'SELECT * FROM BOSTON') Uses familiar Python syntax to manipulate database data Overloads Python functions translating functionality to SQL DATA.shape DATA.head() DATA.describe() DATA.std() DATA.skew() TRAIN, TEST = DATA.split() TRAIN.shape TEST.shape In-database performance – indexes, query optimization, parallelism, partitioning Copyright © 2022, Oracle and/or its affiliates 50 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 44

Slide 44 text

In-database scalable aggregation Example using the crosstab function Oracle Database User tables ONTIME_S = oml.sync(table="ONTIME_S") res = ONTIME_S.crosstab('DEST') type(res) res.head() Source data is a DataFrame, ONTIME_S, which is an Oracle Database table crosstab() function overloaded to accept OML DataFrame objects and transparently generates SQL for scalable processing in Oracle Database Returns an ‘oml.core.frame.DataFrame’ object In-db stats select DEST, count(*) from ONTIME_S group by DEST OML4Py OML Notebooks Copyright © 2022, Oracle and/or its affiliates 51 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 45

Slide 45 text

Goal: Become familiar with creating and using DataFrame proxy objects for exploring and transforming database tables and views Task 1: Import libraries and create Oracle Machine Learning dataFrame proxy object Task 2: Select table columns using proxy object CUST_DF Task 3: Select table rows using proxy object CUST_DF Task 4: Use OML DataFrame proxy objects Task 5: Use the split and kfold functions Task 6: Use the crosstab and pivot_table functions on a dataFrame proxy object Task 7: Use the oml.boxplot and oml.hist functions Task 8: Manage and explore data using transparency layer functions Task 9: Use cx_Oracle functions Lab 2: Select and manipulate data using the Transparency Layer Copyright © 2022, Oracle and/or its affiliates 52 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 46

Slide 46 text

Copyright © 2022, Oracle and/or its affiliates 53 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Let's switch to the notebook for Lab 2, by going back to the main Notebooks listing and clicking on Lab 2.

Slide 47

Slide 47 text

Copyright (c) 2022 Oracle Corporation Copyright © 2022, Oracle and/or its affiliates 54 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Let's review the notebook tasks. Scroll down to follow the Instructor.

Slide 48

Slide 48 text

55 Copyright © 2022, Oracle and/or its affiliates Lab 3: Use in-database algorithms and models Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 49

Slide 49 text

OML4Py 1.0 Machine Learning in-database algorithms • Decision Tree • Naïve Bayes • Generalized Linear Model • Support Vector Machine • Random Forest • Neural Network Regression • Generalized Linear Model • Neural Network • Support Vector Machine Classification Attribute Importance • Minimum Description Length Clustering • Expectation Maximization • Hierarchical k-Means Feature Extraction • Singular Value Decomposition • Explicit Semantic Analysis • Principal Component Analysis via SVD Association Rules • Apriori – Association Rules Anomaly Detection • 1 Class Support Vector Machine Supports automatic data preparation, partitioned model ensembles, integrated text mining Copyright © 2022, Oracle and/or its affiliates 56 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 50

Slide 50 text

Scalable in-database algorithms Example using Support Vector Machine for anomaly detection from oml import svm # create proxy object ONTIME = oml.sync(table='ONTIME') # define model object settings = {'svms_outlier_rate' : 0.01} svm_mod = svm('anomaly_detection', svms_kernel_function = 'dbms_data_mining.svms_linear', **settings) # build anomaly detection model svm_mod = svm_mod.fit(x=ONTIME, y=None) # view model object svm_mod OML4Py OML Notebooks Oracle Autonomous Database User tables In-DB Algorithms Copyright © 2022, Oracle and/or its affiliates 57 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 51

Slide 51 text

Goal: Learn how to build and score using in-database machine learning algorithms, as well as some of the other model-related functionality Task 1: Import libraries Task 2: Work with regression using generalized liner model (GLM) Task 3: Work with clustering using k-Means Task 4: Work with Partitioned Models Task 5: Rank attribute importance using model explainability Lab 3: Using in-database algorithms and models Copyright © 2022, Oracle and/or its affiliates 58 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 52

Slide 52 text

Copyright © 2022, Oracle and/or its affiliates 59 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Let's switch to the notebook for Lab 3, by going back to the main Notebooks listing and clicking on Lab 3.

Slide 53

Slide 53 text

Copyright © 2022, Oracle and/or its affiliates 60 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Copyright (c) 2022 Oracle Corporation Let's review the notebook tasks. Scroll down to follow the Instructor.

Slide 54

Slide 54 text

61 Copyright © 2022, Oracle and/or its affiliates Lab 4: Store and manage Python objects and user-defined functions Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 55

Slide 55 text

Datastore for Python object persistence oml.ds.save() and oml.ds.load() Provide database storage to save/restore Python and OML4Py objects across Python sessions Use cases • Preserve OML4Py objects across Python sessions • Passing arguments to Python functions with embedded Python execution, especially when non-scalar for REST invocation, such as native Python ML models x1 = rf_mod.fit(...) x2 = oml.push(...) oml.ds.save(objs={'x1': x1, 'x2': x2}, name="ds1") oml.ds.load(name="ds1") [‘x1’, ‘x2’] Copyright © 2022, Oracle and/or its affiliates 62 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Python Datastore ds1 {x1,x2}

Slide 56

Slide 56 text

Uses of the OML4Py script repository functions • Create and store user-defined Python functions as scripts in Oracle Database • Grant or revoke the read privilege to a script • List available scripts • Load a script function into the Python environment • Drop a script from the script repository OML4Py script repository Copyright © 2022, Oracle and/or its affiliates 63 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 57

Slide 57 text

Goal: Learn how to store and manage Python objects, both native and from OML, in the database using Datastore, and learn how to store and load custom Python scripts using the OML Python Script Repository. Task 1: Import libraries supporting OML4Py Task 2: Create Pandas DataFrames and load them into Autonomous Database Task 3: Save Python objects to datastore Task 4: Save model objects in a datastore Task 5: Load datastore objects into memory Task 6: View datastores and other details Task 7: View contents of a datastore Task 8: Manage datastore privileges Task 9: Delete datastore content Task 10: Use the Python Script Repository Task 11: Create scripts in repository Task 12: Store a function as a global function Task 13: Drop scripts from the script repository Lab 4: Store and manage Python objects and user-defined functions Copyright © 2022, Oracle and/or its affiliates 64 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 58

Slide 58 text

Copyright © 2022, Oracle and/or its affiliates 65 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Let's switch to the notebook for Lab 4, by going back to the main Notebooks listing and clicking on Lab 4.

Slide 59

Slide 59 text

Copyright © 2022, Oracle and/or its affiliates 66 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Let's review the notebook tasks. Scroll down to follow the Instructor.

Slide 60

Slide 60 text

67 Copyright © 2022, Oracle and/or its affiliates Lab 5: Run user-defined functions using Embedded Python Execution Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 61

Slide 61 text

Embedded Python execution functions for invoking user-defined Python functions oml.do_eval(func[, func_owner, graphics]) Runs the user-defined Python function using a Python engine spawned and controlled by the database environment oml.table_apply(data, func[, func_owner, . . . ]) Runs the user-defined Python function with data pulled from a database table or view using a Python engine spawned and controlled by the database environment oml.row_apply(data, func[, func_owner, . . . ]) Partitions database data into chunks of rows and runs the user-defined Python function on each chunk using Python engines spawned and controlled by the database environment oml.group_apply(data, index, func[, . . . ]) Partitions database data by the column(s) specified in index and runs the user-defined Python function on each partition using Python engines spawned and controlled by the database environment oml.index_apply(times, func[, func_owner, . . . ]) Runs the user-defined Python function multiple times, passing the run index as first argument, using Python engines spawned and controlled by the database environment Copyright © 2022, Oracle and/or its affiliates 68 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 62

Slide 62 text

spawns Example of parallel partitioned data flow using third party package Embedded Python Execution # user-defined function using sklearn def build_lm(dat): from sklearn import linear_model lm = linear_model.LinearRegression() X = dat[['PETAL_WIDTH']] y = dat[['PETAL_LENGTH']] lm.fit(X, y) return lm # select column(s) for partitioning data index = oml.DataFrame(IRIS['SPECIES']) # invoke function in parallel on IRIS table mods = oml.group_apply(IRIS, index, func=build_lm, parallel=2) mods.pull().items() OML4Py Python Engine OML4Py Python Engine OML4Py OML Notebooks REST Interface Oracle Autonomous Database User tables Copyright © 2022, Oracle and/or its affiliates 69 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 63

Slide 63 text

Goal: Learn how to run user-defined Python functions in database-controlled Python engines Task 1: Import OML4Py and supporting libraries and create data table Task 2: Build and score a linear model from sklearn in Python Task 3: Build the model using Embedded Python Execution Task 4: Build one model per species using group_apply function Task 5: Return multiple images from Embedded Python Execution Lab 5: Run user-defined functions using Embedded Python Execution Copyright © 2022, Oracle and/or its affiliates 70 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 64

Slide 64 text

Copyright © 2022, Oracle and/or its affiliates 71 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Let's switch to the notebook for Lab 5 by going back to the main Notebooks listing and clicking on Lab 5.

Slide 65

Slide 65 text

Copyright © 2022, Oracle and/or its affiliates 72 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Let's review the notebook tasks. Scroll down to follow the Instructor.

Slide 66

Slide 66 text

73 Copyright © 2022, Oracle and/or its affiliates Lab 6: Use AutoML Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 67

Slide 67 text

OML4Py AutoML objectives Alleviating pain points • Eliminate repetitive tasks of model building / evaluation to increase user productivity • Apply ML to the ML process to reduce algorithm and hyperparameters search space and reduce compute time and cost • Enable non-expert users to leverage machine learning Copyright © 2022, Oracle and/or its affiliates 74

Slide 68

Slide 68 text

AutoML with OML4Py Increase data scientist productivity – reduce overall compute time Copyright © 2022 Oracle and/or its affiliates. Auto Algorithm Selection • Identify in-database algorithm that achieves highest model quality • Find best algorithm faster than exhaustive search Auto Feature Selection • De-noise data and reduce # of features • Reduce features by identifying the most predictive • Improve performance and accuracy Auto Model Tuning • Significant model accuracy improvement • Automated tuning of hyperparameters • Avoid manual or exhaustive search techniques Enables non-expert users to leverage Machine Learning OML Model Data Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 69

Slide 69 text

Goal: Become familiar with the AutoML workflow and related functions Task 1: Import libraries supporting OML4Py and AutoML Task 2: Automated algorithm selection Task 3: Automated feature selection Task 4: Automated model tuning Task 5: Automated model selection Note: Some AutoML function invocations can take a few minutes to complete. A lot of going on behind the scenes. Please be patient. J Lab 6: Use AutoML Copyright © 2022, Oracle and/or its affiliates 76 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 70

Slide 70 text

Copyright © 2022, Oracle and/or its affiliates 77 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Let's switch to the notebook for Lab 6, by going back to the main Notebooks listing and clicking on Lab 6.

Slide 71

Slide 71 text

Copyright (c) 2022 Oracle Corporation Copyright © 2022, Oracle and/or its affiliates 78 Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature Let's review the notebook tasks. Scroll down to follow the Instructor.

Slide 72

Slide 72 text

80 Copyright © 2022, Oracle and/or its affiliates Bonus Lab: Use OML AutoML UI Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 73

Slide 73 text

In the Home page of OML Notebooks, click on the AutoML UI link Copyright © 2022, Oracle and/or its affiliates 81 Click on AutoML either from the Hamburger menu or from Quick Actions

Slide 74

Slide 74 text

In the AutoML Experiments screen, click "Create" to create a new one Copyright © 2022, Oracle and/or its affiliates 82 1. Click on +Create 2. Give the Experiment a name 3. Click on the Loupe to search for a Data Source

Slide 75

Slide 75 text

In the menu that appears, select: Schema = SH & Table = SUPPLEMENTARY_DEMOGRAPHICS Copyright © 2022, Oracle and/or its affiliates 83 1. Click on the "SH" Schema 2. Select the "SUPPLEMENTARY_DEMOGRAPHICS" table and click the "OK" button

Slide 76

Slide 76 text

In the Create Experiments screen, enter the Predict, Case ID, and adjust performance settings Copyright © 2022, Oracle and/or its affiliates 84 1. For the "Predict" attribute, select AFFINITY_CARD from the pull-down menu 2. For the "Case ID" attribute, select CUST_ID from the pull-down menu 3. Expand the "Additional Settings" and reduce the Maximum Top Models to "2" to save time in this exercise. 4. Change the "Database Service Level" to Medium to get increased parallelism

Slide 77

Slide 77 text

We are ready to start the Experiment Click on the Start -> Faster Results Copyright © 2022, Oracle and/or its affiliates 85 1. Click on Start 2. Click on Faster Results to make sure we have a quick result for this Session 3. Experiment will start

Slide 78

Slide 78 text

The Progress Report will open. It can be closed and opened at anytime. Copyright © 2022, Oracle and/or its affiliates 86 The Progress Report is shown in a window that can be closed. Clicking on "Detail" opens it again.

Slide 79

Slide 79 text

Completed vs Running Steps Copyright © 2022, Oracle and/or its affiliates 87 Checkboxes are shown for completed steps, while running steps show an animation

Slide 80

Slide 80 text

Top algorithms selected by AutoML Copyright © 2022, Oracle and/or its affiliates 88 Only the Top algorithms identified in the "Algorithm Selection" phase are shown in the Leader Board

Slide 81

Slide 81 text

A completed Experiment looks like this Copyright © 2022, Oracle and/or its affiliates 89 The Experiment finishes when you see the "Completed" message at the top Checkboxes are shown for all completed steps

Slide 82

Slide 82 text

2. After an experiment run is completed, the Features grid displays an additional column "Importance". Feature Importance indicates the overall level of sensitivity of prediction to a particular feature. The value is always depicted in the range 0 to 1, with values closer to 1 being more important. Let's check the global Feature Importance Copyright © 2022, Oracle and/or its affiliates 90 1. Scroll down to reveal the Features list

Slide 83

Slide 83 text

Let's open the Model Detail to inspect the Model Copyright © 2022, Oracle and/or its affiliates 91 Click on the Naïve Bayes model name in blue

Slide 84

Slide 84 text

Review the Model Detail – Prediction Impacts Copyright © 2022, Oracle and/or its affiliates 92 A new window with the Model Details show the Prediction Impacts of the Attributes on this specific model. It uses OML's Machine Learning Explainability module to provide model-agnostic functionality to identify the important features that impact a trained model’s predictions.

Slide 85

Slide 85 text

Review the Model Detail – Confusion Matrix Copyright © 2022, Oracle and/or its affiliates 93 The Confusion Matrix shows an evaluation of the Model on the Validation Data selected by AutoML at the end of the process

Slide 86

Slide 86 text

94 Copyright © 2022, Oracle and/or its affiliates Bonus Lab: Create an auto-generated OML notebook from your AutoML UI model Just joining? Login with your Oracle Account and Launch Free Trial Workshop: https://bit.ly/oml4pyhol Technical problems? Questions about Oracle Machine Learning? Talk to us via the Zoom "Q&A" feature

Slide 87

Slide 87 text

Auto-generation of an OML notebook with OML4Py Let's see how to access a Notebook with the entire model building process Copyright © 2022, Oracle and/or its affiliates 95 1. Click anywhere on the model’s line to highlight the it (the row will become a shade of blue) Note: do not click model name since this will open the model details 2. The Create Notebook button will become available. Click on it to get to the Create Notebook form.

Slide 88

Slide 88 text

Auto-generation of an OML notebook with OML4Py Give the new Notebook a name Copyright © 2022, Oracle and/or its affiliates 96 Click on OK to Create the Notebook In the new "Create Notebook" window, you can optionally change the name if you want, or accept the default

Slide 89

Slide 89 text

Auto-generation of an OML notebook with OML4Py Give the new Notebook a name Copyright © 2022, Oracle and/or its affiliates 97 The message at the top of the screen confirms that the notebook was created successfully

Slide 90

Slide 90 text

Let's check the notebook code We need to get to the Notebooks list Copyright © 2022, Oracle and/or its affiliates 98 Click on the "Hamburger Menu" on the top left corner of the screen. It reveals the section in black. Select Notebooks from there

Slide 91

Slide 91 text

The auto-generated notebook is available Let's access the Notebook listed Copyright © 2022, Oracle and/or its affiliates 99 Click on the notebook name to open it

Slide 92

Slide 92 text

Check the notebook output We can now verify each paragraph Copyright © 2022, Oracle and/or its affiliates 100 1. Once inside the notebook click on the top right gear icon to check the Interpreter Bindings icon 2. Make sure that at least one of the OML interpreters is Blue, preferably the xxxx_medium interpreter. Then click on Save.

Slide 93

Slide 93 text

The notebook is opened, but it has not been run yet Let's run it so we can see all statistics and the resulting output Copyright © 2022, Oracle and/or its affiliates 101 Click on the "Play" button next to the notebook's name to run all paragraphs Then confirm it by clicking OK

Slide 94

Slide 94 text

Check the Notebook output We can now verify each paragraph Copyright © 2022, Oracle and/or its affiliates 102 This first section contains the metadata about this notebook

Slide 95

Slide 95 text

Check the notebook output We can now verify each paragraph Copyright © 2022, Oracle and/or its affiliates 103 This section defines the dataset as needed by the model, with the required columns only

Slide 96

Slide 96 text

Check the notebook output We can now verify each paragraph Copyright © 2022, Oracle and/or its affiliates 104 This section splits the target column from the input attributes, to prepare the Training data for the model Using the algorithm settings identified by AutoML to be the best ones for this model, we proceed to building the model (nb_mod.fit)

Slide 97

Slide 97 text

Check the Notebook output We can now verify each paragraph Copyright © 2022, Oracle and/or its affiliates 105 This section shows the model details. You can scroll down inside the paragraph to see more information about the model Metadata This highlights that the prediction section will use the same input data for scoring. You can provide a different table for it, by using: my_scoring_data = oml.sync(table="MY_SCORING").

Slide 98

Slide 98 text

Check the Notebook output We can now verify each paragraph Copyright © 2022, Oracle and/or its affiliates 106 This section runs a prediction on the original build data. It also selects only the PREDICTION column, and brings it into Python's memory for use with scikit-learn in the next paragraph This paragraph imports the scikit-learn package and uses the metrics.balanced_accuracy_score function to check the predictions quality if one were to use the same input data as Test Data. We expect a value similar to the one we see in the OML AutoML UI Leader Board, but it can be slightly different since that one is not computed over the entire dataset, but on a validation subset (or cross-validation) generated by AutoML.

Slide 99

Slide 99 text

Bonus Round 1 – check the predictions and probabilities Add your own code to the Notebook to check the predictions, probabilities and Unique IDs Copyright © 2022, Oracle and/or its affiliates 107 Type this code on a new paragraph after running the entire notebook to check the predictions and probabilities without downloading the results into Python's local memory. We will use the special option for adding some columns from the table being scored into the final dataset, and check the probability of that specific prediction. z.show( nb_mod.predict(build_data, proba=True, supplemental_cols=build_data[['CUST_ID','EDUCATION','HOUSEHOLD_SIZE']]) )

Slide 100

Slide 100 text

Bonus Round 2 – check the predictions and probabilities Add your own code to the Notebook to check the probabilities of 0 and 1, and Unique IDs Copyright © 2022, Oracle and/or its affiliates 108 Type this code on a new paragraph after running the entire Notebook, to check the predictions and probabilities without downloading the results into Python's local memory. We will use a different function, prediction_proba, that can return the probability for each of the categories in the Target (in our case "0" or "1"). z.show( nb_mod.predict_proba(build_data, supplemental_cols=build_data[['CUST_ID','EDUCATION','HOUSEHOLD_SIZE']]).round(8) )

Slide 101

Slide 101 text

Bonus Round 3 – check the prediction details and probabilities Add your own code to the Notebook to check the prediction details and probabilities Copyright © 2022, Oracle and/or its affiliates 109 Type this code on a new paragraph after running the entire notebook, to check the predictions, prediction details and probabilities without downloading the results into Python's local memory. This option now uses the special topN_attrs option to show the top attributes that contributed to that specific customer's prediction, also known as the prediction details. z.show( nb_mod.predict(build_data, proba=True, supplemental_cols=build_data['CUST_ID'], topN_attrs=2).round(4) )

Slide 102

Slide 102 text

Wrap Up Copyright © 2022, Oracle and/or its affiliates 111

Slide 103

Slide 103 text

Oracle LiveLabs – Oracle’s Solution Showcase bit.ly/golivelabs • Experience Oracle’s cloud and on-premises products and technologies. No software to download or install • On-demand hands-on workshops created by Oracle’s experts to run on Oracle • Catalog is actively curated and covers a wide and expanding range of Oracle technologies • Free and available 24/7, globally • Fast-track your journey to Oracle Cloud

Slide 104

Slide 104 text

113 Copyright © 2022, Oracle and/or its affiliates Want to Learn More? If you did not have the opportunity to follow along today, you still can do this anytime. Just login with your oracle.com account and click on "Launch Free Trial Workshop": https://bit.ly/oml4pyhol

Slide 105

Slide 105 text

OML LiveLabs and Additional Resources Webpage: https://oracle.com/goto/machine-learning Blogs: https://bit.ly/omlblogs Machine Learning LiveLabs Github oracle-db-examples repository 114 OML Notebooks 70+ included template examples Copyright © 2022, Oracle and/or its affiliates | All Rights Reserved. OML Office Hours https://bit.ly/omlofficehours https://bit.ly/omlgithub https://bit.ly/omllivelabs

Slide 106

Slide 106 text

Make the best use of your Free Tier Account: • Please sign out of Oracle Machine Learning on your browser after this session • Also, please shut down your Autonomous Database if you are not using it. Any data and machine learning projects will still be there when you start it up. Final thoughts Copyright © 2022, Oracle and/or its affiliates 115

Slide 107

Slide 107 text

Thank you! Hands-On Lab: Introduction to Oracle Machine Learning for Python on Autonomous Database Marcos Arancibia Product Manager, Oracle Machine Learning Mark Hornick, Sherry LaMonica Oracle Machine Learning product team

Slide 108

Slide 108 text

No content