Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hands-On Lab: Introduction to Oracle Machine Learning for Python on Autonomous Database

Hands-On Lab: Introduction to Oracle Machine Learning for Python on Autonomous Database

In this Introductory Oracle Machine Learning workshop we focused on the Python API - OML4Py. If you're interested in machine learning and Python in the Oracle environment, access this hands-on lab to experience the OML Notebooks interface and prepare data and build machine learning models in the database.

You will learn to provision your Autonomous Database and create OML users, load sample data from Github, manipulate database tables as Pandas DataFrame proxy objects, build powerful machine learning models, and use AutoML through the Python API and no-code OML AutoML UI.

After participating in this workshop, you will be able to:
- Select and manipulate Database data directly from Python using Pandas DataFrame proxy objects
- Train, test, and score using in-database machine learning models
- Store and manage Python objects and user-defined functions in the database
- Run and deploy those user-defined Python functions using Embedded Python Execution
- Use AutoML from the Python API and the no-code AutoML UI to create ML models in an automated fashion

We use Oracle Autonomous Database for all exercises, and suggest you create an Oracle Cloud Free Tier account ahead of time so you can jump right into the training: https://signup.cloud.oracle.com/

Marcos Arancibia

February 28, 2022
Tweet

More Decks by Marcos Arancibia

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. Roles & Names 3 Copyright © 2022, Oracle and/or its

    affiliates Marcos Presenter Mark Q&A Sherry Technical Support
  4. • 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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.
  15. 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
  16. 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"
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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!
  32. 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
  33. 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
  34. 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
  35. 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.
  36. 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.
  37. 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
  38. 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
  39. 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.
  40. 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.
  41. 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
  42. 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
  43. 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
  44. 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
  45. 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.
  46. 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.
  47. 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
  48. 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
  49. 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
  50. 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
  51. 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.
  52. 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.
  53. 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
  54. 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}
  55. 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
  56. 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
  57. 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.
  58. 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.
  59. 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
  60. 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
  61. 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
  62. 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
  63. 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.
  64. 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.
  65. 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
  66. 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
  67. 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
  68. 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
  69. 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.
  70. 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.
  71. 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
  72. 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
  73. 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
  74. 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
  75. 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
  76. 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
  77. 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.
  78. Completed vs Running Steps Copyright © 2022, Oracle and/or its

    affiliates 87 Checkboxes are shown for completed steps, while running steps show an animation
  79. 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
  80. 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
  81. 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
  82. 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
  83. 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.
  84. 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
  85. 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
  86. 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.
  87. 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
  88. 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
  89. 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
  90. 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
  91. 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.
  92. 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
  93. 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
  94. 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
  95. 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)
  96. 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").
  97. 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.
  98. 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']]) )
  99. 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) )
  100. 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) )
  101. 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
  102. 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
  103. 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
  104. 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
  105. 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