Skip to content

Commit ff1cd30

Browse files
authored
Update ML demos for 23c and OML4Py 2.0 (#275)
Large update to all OML4SQL Demos for 23c with added algorithms like Survival Analysis and Time Series Regression, update ML demos for 23c and new notebooks for OML4Py 2.0 features including DATE and DATETIME support
1 parent f327247 commit ff1cd30

File tree

52 files changed

+22003
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+22003
-2
lines changed

machine-learning/notebooks/python/OML4Py Date and Time Classes.json

+1,803
Large diffs are not rendered by default.

machine-learning/notebooks/python/OML4Py Time Series ESM.json

+947
Large diffs are not rendered by default.

machine-learning/notebooks/sql/OML Export and Import Serialized Models.json

+2,321
Large diffs are not rendered by default.

machine-learning/notebooks/sql/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The specific denomination "21c or 23c" in the name of the file means that the al
1919

2020
See [Oracle Machine Learning Notebooks - Get Started](https://docs.oracle.com/en/database/oracle/machine-learning/oml-notebooks/) for more information.
2121

22-
Last updated on: April 2023
22+
Last updated on: June 2023
2323

2424
#### Copyright (c) 2023 Oracle Corporation and/or its affilitiates.
2525

machine-learning/oml-services/OML Export and Import Serialized Models.json

+2,321
Large diffs are not rendered by default.

machine-learning/oml-services/oml4sql-notebook-exporting-serialized-models.json

-1
This file was deleted.

machine-learning/sql/23c/README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Oracle Database 23c Machine Learning for SQL examples
2+
Oracle Machine Learning for SQL is part of the Oracle Machine Learning family of technologies, and is the fastest way to access the heart of the Machine Learning inside every Oracle Database.
3+
4+
Following Oracle's philosophy of moving the algorithms and not the data, the execution of these 30+ parallel, scalable in-Database implementations of machine learning algorithms minimizes or eliminates data movement, achieving scalability, security, and accelerated time-to-model deployment.
5+
6+
Oracle also provides easy mechanism for running R-extensible scripts directly inside the Oracle Database.
7+
8+
**The following are a list of demos containing SQL code for learning about (OML4SQL)**
9+
10+
Files on the current folder:
11+
* dmsh.sql - Setup - Creates Demo Views and Tables
12+
* dmshgrants.sql - Setup - Grants Privileges to Users
13+
* oml4sql-anomaly-detection-1class-svm.sql - Anomaly Detection - One Class SVM Algorithm
14+
* oml4sql-association-rules.sql - Association Rules - Apriori Algorithm
15+
* oml4sql-attribute-importance.sql - Attribute Importance - "EXPLAIN" MDL function
16+
* oml4sql-classification-decision-tree.sql - Classification - Decision Tree Algorithm
17+
* oml4sql-classification-glm.sql - Classification - Generalized Linear Model Algorithm
18+
* oml4sql-classification-naive-bayes.sql - Classification - Naïve Bayes Algorithm
19+
* oml4sql-classification-neural-networks.sql - Classification - Neural Networks Algorithm
20+
* oml4sql-classification-random-forest.sql - Classification - Random Forest Algorithm
21+
* oml4sql-classification-regression-xgboost.sql - Classification and Regression - XGBoost Algorithm
22+
* oml4sql-classification-svm.sql - Classification - SVM Algorithm
23+
* oml4sql-classification-text-mining-svm.sql - Classification - SVM Algorithm with Text Mining
24+
* oml4sql-clustering-expectation-maximization.sql - Clustering - Expectation-Maximization Algorithm
25+
* oml4sql-clustering-kmeans-star-schema.sql - Clustering - K-Means Algorithm
26+
* oml4sql-clustering-kmeans.sql - Clustering - K-Means Algorithm
27+
* oml4sql-clustering-ocluster.sql - Clustering - O-Cluster Algorithm
28+
* oml4sql-cross-validation-decision-tree.sql - Cross-Validation - Decision Tree Algorithm
29+
* oml4sql-feature-extraction-cur.sql - Feature and Row Extraction - CUR Decomposition Algorithm
30+
* oml4sql-feature-extraction-nmf.sql - Feature Extraction - Non-Negative Matrix Factorization Algorithm
31+
* oml4sql-feature-extraction-svd.sql - Feature Extraction - Singular Value Decomposition
32+
* oml4sql-feature-extraction-text-mining-esa.sql - Feature Extraction - ESA Algorithm for Text Mining
33+
* oml4sql-feature-extraction-text-mining-nmf.sql - Feature Extraction - NMF Algorithm with Text Mining
34+
* oml4sql-feature-extraction-text-term-extraction.sql - Feature Extraction - Text Term Extraction
35+
* oml4sql-partitioned-models-svm.sql - Partitioned Models - Support Vector Machine Algorithm
36+
* oml4sql-r-extensible-algorithm-registration.sql - OML R Extensible - Algorithm Registration
37+
* oml4sql-r-extensible-association-rules.sql - OML R Extensible - Association Rules Algorithm
38+
* oml4sql-r-extensible-attribute-importance-via-rf.sql - OML R Extensible - Attribute Importance via RF Algorithm
39+
* oml4sql-r-extensible-glm.sql - OML R Extensible - Generalized Linear Model Algorithm
40+
* oml4sql-r-extensible-kmeans.sql - OML R Extensible - K-Means Algorithm
41+
* oml4sql-r-extensible-principal-components.sql - OML R Extensible - Principal Components Algorithm
42+
* oml4sql-r-extensible-regression-neural-networks.sql - OML R Extensible - Regression - Neural Networks Algorithm
43+
* oml4sql-r-extensible-regression-tree.sql - OML R Extensible - Regression Tree Algorithm
44+
* oml4sql-regression-glm.sql - Regression - Generalized Linear Model Algorithm
45+
* oml4sql-regression-neural-networks.sql - Regression - Neural Networks Algorithm
46+
* oml4sql-regression-random-forest.sql - Regression - Random Forest Algorithm
47+
* oml4sql-regression-svm.sql - Regression - SVM Algorithm
48+
* oml4sql-singular-value-decomposition.sql - SVD Algorithm
49+
* oml4sql-survival-analysis-xgboost.sql - Survival Analysis with AFT (Accelerated Failure Time) via XGBoost Algorithm
50+
* oml4sql-time-series-esm-auto-model-search.sql - Time Series - Exponential Smoothing with Auto Model Search
51+
* oml4sql-time-series-exponential-smoothing.sql - Time Series - Exponential Smoothing Algorithm
52+
* oml4sql-time-series-mset.sql - Time Series - MSET Multivariate State Estimation Technique Algorithm
53+
* oml4sql-time-series-regression-dataset.sql - Time Series Regression - Dataset
54+
* oml4sql-time-series-regression.sql - Time Series Regression - Using a combination of ESM and GLM algorithms
55+
56+
#### Copyright (c) 2023 Oracle Corporation and its affiliates
57+
58+
##### [The Universal Permissive License (UPL), Version 1.0](https://oss.oracle.com/licenses/upl/)
59+

machine-learning/sql/23c/dmsh.sql

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
-----------------------------------------------------------------------
2+
-- Oracle Machine Learning for SQL (OML4SQL) 23c
3+
--
4+
-- Setup - Creates Demo Views and Tables - dmsh.sql
5+
--
6+
-- Copyright (c) 2023 Oracle Corporation and/or its affilitiates.
7+
--
8+
-- The Universal Permissive License (UPL), Version 1.0
9+
--
10+
-- https://oss.oracle.com/licenses/upl/
11+
-----------------------------------------------------------------------
12+
--
13+
--
14+
-- dmsh.sql
15+
--
16+
--
17+
-- NAME
18+
-- dmsh.sql
19+
--
20+
-- DESCRIPTION
21+
-- This script creates views and tables using SH data
22+
-- in the schema of the data mining user. These tables/views
23+
-- are the datasets used by the Oracle Data Mining demo programs.
24+
-- This script also creates a text policy for text mining.
25+
-- NOTES
26+
-- The script assumes that the full SH schema is already created and the
27+
-- necessary SELECTs have been granted (See dmshgrants.sql). This script runs in
28+
-- the schema of the data mining user.
29+
-- mining_data_*_v views : Used for mining (no text)
30+
-- mining_*_text views: Used for mining with text
31+
--
32+
--------------------------------------------------------------------------------
33+
--
34+
-- Creates data mining views on SH data
35+
--
36+
37+
--------------------------------------------------------------------------------
38+
-- View to join and filter data
39+
-- CUST_YEAR_OF_BIRTH column is transformed to an AGE
40+
CREATE OR REPLACE VIEW mining_data AS
41+
SELECT
42+
a.CUST_ID, a.CUST_GENDER,
43+
2003-a.CUST_YEAR_OF_BIRTH AGE,
44+
a.CUST_MARITAL_STATUS, c.COUNTRY_NAME, a.CUST_INCOME_LEVEL, b.EDUCATION,
45+
b.OCCUPATION, b.HOUSEHOLD_SIZE, b.YRS_RESIDENCE, b.AFFINITY_CARD,
46+
b.BULK_PACK_DISKETTES, b.FLAT_PANEL_MONITOR, b.HOME_THEATER_PACKAGE,
47+
b.BOOKKEEPING_APPLICATION, b.PRINTER_SUPPLIES, b.Y_BOX_GAMES,
48+
b.os_doc_set_kanji, b.comments
49+
FROM
50+
sh.customers a,
51+
sh.supplementary_demographics b,
52+
sh.countries c
53+
WHERE
54+
a.CUST_ID = b.CUST_ID
55+
AND a.country_id = c.country_id
56+
AND a.cust_id between 100001 and 104500;
57+
58+
--------------------------------------------------------------------------------
59+
-- Build, test, and apply views (with text)
60+
-- Build, test, and apply datasets are made non-overlapping by using
61+
-- a predicate on cust_id.
62+
63+
CREATE OR REPLACE VIEW mining_build_text AS
64+
SELECT *
65+
FROM mining_data
66+
WHERE cust_id between 101501 and 103000;
67+
68+
CREATE OR REPLACE VIEW mining_test_text AS
69+
SELECT *
70+
FROM mining_data
71+
WHERE cust_id between 103001 and 104500;
72+
73+
CREATE OR REPLACE VIEW mining_apply_text AS
74+
SELECT *
75+
FROM mining_data
76+
WHERE cust_id between 100001 and 101500;
77+
78+
--------------------------------------------------------------------------------
79+
-- Build, test, and apply views
80+
-- Same as above, but no text - COMMENTS column removed
81+
82+
CREATE OR REPLACE VIEW mining_data_build_v AS
83+
SELECT CUST_ID, CUST_GENDER, AGE, CUST_MARITAL_STATUS, COUNTRY_NAME,
84+
CUST_INCOME_LEVEL, EDUCATION, OCCUPATION, HOUSEHOLD_SIZE,
85+
YRS_RESIDENCE, AFFINITY_CARD, BULK_PACK_DISKETTES, FLAT_PANEL_MONITOR,
86+
HOME_THEATER_PACKAGE, BOOKKEEPING_APPLICATION, PRINTER_SUPPLIES,
87+
Y_BOX_GAMES, OS_DOC_SET_KANJI
88+
FROM mining_build_text;
89+
90+
CREATE OR REPLACE VIEW mining_data_test_v AS
91+
SELECT CUST_ID, CUST_GENDER, AGE, CUST_MARITAL_STATUS, COUNTRY_NAME,
92+
CUST_INCOME_LEVEL, EDUCATION, OCCUPATION, HOUSEHOLD_SIZE,
93+
YRS_RESIDENCE, AFFINITY_CARD, BULK_PACK_DISKETTES, FLAT_PANEL_MONITOR,
94+
HOME_THEATER_PACKAGE, BOOKKEEPING_APPLICATION, PRINTER_SUPPLIES,
95+
Y_BOX_GAMES, OS_DOC_SET_KANJI
96+
FROM mining_test_text;
97+
98+
CREATE OR REPLACE VIEW mining_data_apply_v AS
99+
SELECT CUST_ID, CUST_GENDER, AGE, CUST_MARITAL_STATUS, COUNTRY_NAME,
100+
CUST_INCOME_LEVEL, EDUCATION, OCCUPATION, HOUSEHOLD_SIZE,
101+
YRS_RESIDENCE, AFFINITY_CARD, BULK_PACK_DISKETTES, FLAT_PANEL_MONITOR,
102+
HOME_THEATER_PACKAGE, BOOKKEEPING_APPLICATION, PRINTER_SUPPLIES,
103+
Y_BOX_GAMES, OS_DOC_SET_KANJI
104+
FROM mining_apply_text;
105+
106+
--------------------------------------------------------------------------------
107+
-- Data for one class model
108+
-- Only data for positive affinity card (one class) is used.
109+
110+
CREATE OR REPLACE VIEW mining_data_one_class_v AS
111+
SELECT CUST_ID, CUST_GENDER, AGE, CUST_MARITAL_STATUS, COUNTRY_NAME,
112+
CUST_INCOME_LEVEL, EDUCATION, OCCUPATION, HOUSEHOLD_SIZE, YRS_RESIDENCE
113+
FROM mining_data_build_v
114+
WHERE affinity_card = 1;
115+
116+
--------------------------------------------------------------------------------
117+
--
118+
-- Create view mining_data_build_parallel_v with a parallel hint
119+
--
120+
--------------------------------------------------------------------------------
121+
CREATE or REPLACE VIEW mining_data_build_parallel_v AS SELECT /*+ parallel (4)*/ * FROM mining_data_build_v;
122+
123+
--------------------------------------------------------------------------------
124+
--
125+
-- Create view mining_data_one_class_pv with a parallel hint
126+
--
127+
--------------------------------------------------------------------------------
128+
CREATE or REPLACE VIEW mining_data_one_class_pv AS SELECT /*+ parallel (4)*/ * FROM mining_data_one_class_v;
129+
130+
--------------------------------------------------------------------------------
131+
--
132+
-- Create view mining_data_test_parallel_v with a parallel hint
133+
--
134+
--------------------------------------------------------------------------------
135+
CREATE or REPLACE VIEW mining_data_test_parallel_v AS SELECT /*+ parallel (4)*/ * FROM mining_data_test_v;
136+
137+
--------------------------------------------------------------------------------
138+
--
139+
-- Create view mining_data_apply_parallel_v with a parallel hint
140+
--
141+
--------------------------------------------------------------------------------
142+
CREATE or REPLACE VIEW mining_data_apply_parallel_v AS SELECT /*+ parallel (4)*/ * FROM mining_data_apply_v;
143+
144+
--------------------------------------------------------------------------------
145+
--
146+
-- Create view mining_test_text_parallel with a parallel hint
147+
--
148+
--------------------------------------------------------------------------------
149+
CREATE or REPLACE VIEW mining_test_text_parallel AS SELECT /*+ parallel (4)*/ * FROM mining_test_text;
150+
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-----------------------------------------------------------------------
2+
-- Oracle Machine Learning for SQL (OML4SQL) 23c
3+
--
4+
-- Setup - Grants Privileges to Users - dmshgrants.sql
5+
--
6+
-- Copyright (c) 2023 Oracle Corporation and/or its affilitiates.
7+
--
8+
-- The Universal Permissive License (UPL), Version 1.0
9+
--
10+
-- https://oss.oracle.com/licenses/upl/
11+
-----------------------------------------------------------------------
12+
--
13+
--
14+
-- dmshgrants.sql
15+
--
16+
-- Copyright (c) 2001, 2010, 2021, Oracle and/or its affiliates.
17+
-- All rights reserved.
18+
--
19+
-- NAME
20+
-- dmshgrants.sql
21+
--
22+
-- DESCRIPTION
23+
-- This script grants SELECT on SH tables and SYS privileges
24+
-- required to run the Oracle Data Mining demo programs
25+
--
26+
-- The script is to be run in SYS account
27+
--
28+
-- NOTES
29+
-- &&1 Name of the DM user
30+
--
31+
--------------------------------------------------------------------------------
32+
DEFINE DMUSER = &&1
33+
34+
grant create session to &DMUSER
35+
/
36+
grant create table to &DMUSER
37+
/
38+
grant create view to &DMUSER
39+
/
40+
grant create mining model to &DMUSER
41+
/
42+
grant execute on ctxsys.ctx_ddl to &DMUSER
43+
/
44+
45+
GRANT SELECT ON sh.customers TO &DMUSER
46+
/
47+
GRANT SELECT ON sh.sales TO &DMUSER
48+
/
49+
GRANT SELECT ON sh.products TO &DMUSER
50+
/
51+
GRANT SELECT ON sh.supplementary_demographics TO &DMUSER
52+
/
53+
GRANT SELECT ON sh.countries TO &DMUSER
54+
/

0 commit comments

Comments
 (0)