|
| 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 | + |
0 commit comments