Skip to content

Commit ae82232

Browse files
authoredOct 24, 2024
Updates and fixes to Sample Code (#399)
Updates and fixes to two sets of examples for SQL code: Anomaly Detection and ESM Auto Model search.
1 parent 966a99f commit ae82232

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed
 

‎machine-learning/sql/23ai/oml4sql-anomaly-detection-em.sql

+9-17
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@
99
--
1010
-- https://oss.oracle.com/licenses/upl
1111
-----------------------------------------------------------------------
12-
SET ECHO ON
13-
SET FEEDBACK 1
14-
SET NUMWIDTH 10
15-
SET LINESIZE 80
16-
SET TRIMSPOOL ON
17-
SET TAB OFF
18-
SET PAGESIZE 100
19-
SET serveroutput ON
20-
SET pages 10000
12+
2113
-----------------------------------------------------------------------
2214
-- SAMPLE PROBLEM
2315
-----------------------------------------------------------------------
@@ -101,9 +93,9 @@ END;
10193
-- DISPLAY MODEL DETAILS
10294
--
10395

104-
SELECT *
105-
FROM TABLE(dbms_data_mining.get_model_details_global('CUSTOMERS360MODEL_AD'))
106-
ORDER BY global_detail_name;
96+
SELECT NAME, NUMERIC_VALUE
97+
FROM DM$VGCUSTOMERS360MODEL_AD
98+
ORDER BY NAME;
10799

108100
---------------------------------------------
109101
-- DISPLAY THE TOP 5 MOST ANOMALOUS CUSTOMERS
@@ -114,7 +106,7 @@ FROM (SELECT CUST_ID, round(prob_anomalous,2) prob_anomalous,
114106
YRS_RESIDENCE, CUST_MARITAL_STATUS,
115107
rank() over (ORDER BY prob_anomalous DESC) rnk
116108
FROM (SELECT CUST_ID, HOUSEHOLD_SIZE, YRS_RESIDENCE, CUST_GENDER, CUST_MARITAL_STATUS,
117-
prediction_probability(CUSTOMERS360MODEL, '0' USING *) prob_anomalous
109+
prediction_probability(CUSTOMERS360MODEL_AD, '0' USING *) prob_anomalous
118110
FROM CUSTOMERS360_V))
119111
WHERE rnk <= 5
120112
ORDER BY prob_anomalous DESC;
@@ -147,10 +139,10 @@ SELECT CUST_ID, PREDICTION,
147139
RTRIM(TRIM(SUBSTR(OUTPRED."Attribute2",17,100)),'rank="2"/>') SECOND_ATTRIBUTE,
148140
RTRIM(TRIM(SUBSTR(OUTPRED."Attribute3",17,100)),'rank="3"/>') THIRD_ATTRIBUTE
149141
FROM (SELECT CUST_ID,
150-
PREDICTION(CUSTOMERS360MODEL USING *) PREDICTION,
151-
PREDICTION_DETAILS(CUSTOMERS360MODEL, '0' USING *) PREDICTION_DETAILS
142+
PREDICTION(CUSTOMERS360MODEL_AD USING *) PREDICTION,
143+
PREDICTION_DETAILS(CUSTOMERS360MODEL_AD, '0' USING *) PREDICTION_DETAILS
152144
FROM CUSTOMERS360_V
153-
WHERE PREDICTION_PROBABILITY(CUSTOMERS360MODEL, '0' USING *) > 0.50
145+
WHERE PREDICTION_PROBABILITY(CUSTOMERS360MODEL_AD, '0' USING *) > 0.50
154146
AND OCCUPATION = 'TechSup'
155147
ORDER BY CUST_ID) OUT,
156148
XMLTABLE('/Details'
@@ -164,4 +156,4 @@ FETCH FIRST 10 ROWS ONLY;
164156

165157
-----------------------------------------------------------------------
166158
-- End of script
167-
-----------------------------------------------------------------------
159+
-----------------------------------------------------------------------

‎machine-learning/sql/23ai/oml4sql-time-series-esm-auto-model-search.sql

+3-7
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ ORDER BY setting_name;
7878
-- COMPUTED SETTINGS AND OTHER GLOBAL STATISTICS
7979
--
8080

81-
SELECT TYPE, name, nval, sval
82-
FROM DM$PPESM_SALES_FORECAST_1
83-
ORDER BY TYPE, name;
84-
85-
SELECT global_detail_name, ROUND(global_detail_value,3) global_detail_value
86-
FROM table(dbms_data_mining.get_model_details_global('ESM_SALES_FORECAST_1'))
87-
ORDER BY global_detail_name;
81+
SELECT name, ROUND(numeric_value,3) numeric_value, string_value
82+
FROM DM$VGESM_SALES_FORECAST_1
83+
ORDER BY name;
8884
/
8985

9086
-----------------------------------------------------------------------

0 commit comments

Comments
 (0)
Please sign in to comment.