This is an excerpt from Dr. Ham's premier book
"Oracle
Data Mining: Mining Gold from your Warehouse".
ODMr
gives you three ways to deploy the results of the applied models.
You can save the result as a text file or spreadsheet, publish the
result to Oracle Discoverer, or export the model to another Oracle
database for scoring.
In the clustering apply examples
shown above, the result viewer has an icon.
Publishing to a File
Selecting this button launches a wizard that lets you choose either
Excel format (tab
delimited) or Text format (comma, vertical bar, hyphen, period or
space delimited), allowing you to store the data on your local hard
drive or network.
Using
the Discoverer Gateway for Publication
The
second way to deploy your results is via Publish to Discoverer
Gateway.
In
the result viewer you will see a Publish tab which starts the
Publish to Discoverer wizard.
You
can choose to create either a table or view, and after creating the
output you can see the object in the ODMr
navigator tree under Discoverer
Objects.
Having the table or view in a location separate from the other
tables in the schema makes it easier for Oracle Discoverer
Gateway to pick the table and add it to an End User Layer(EUL).
Publishing to an Oracle Database
The
third method for deployment involves exporting a model to another
Oracle database for scoring. Using Data Pump technology,
ODMr
supports export and
import of all models. The following explanation of exporting
and importingODM
models
is from the Oracle 10G
Rel 2 Tutorial available at:
http://www.oracle.com/technology/products/bi/odm/odminer.html
.
You may develop models in one Oracle Enterprise
Edition database, but you may want to apply the model to data in a
different (production) database. Oracle 10g Release 2 provides
native import and export of all ODM models,
using Oracle Data Pump Technology, for the purpose of moving a model
from one database to another.
NOTE: Whatever
transformationsare used to prepare the source data for
the building of the model must be repeated exactly in the production
environment before the model can be used to score new data.
When a DBA exports and imports an entire database or
an entire schema using Oracle Data Pump, then any data mining models
contained in the database or schema are transferred.
You can export an individual model or several models
using the Oracle Data Mining API at the command line level. There is
no wizard in the Oracle Data Miner GUI to accomplish such a
transfer.
The export operation creates a file in a folder that
must exist prior to the export; it is referenced in the PL/SQL
export function
as a
directory object. A directory object is a logical name in the
database that is mapped to the operating system file structure.
Similarly, the database into which the model is imported must also
have a directory object referencing the storage location of the file
created by the export function.
Moreover, the tablespace name for the exporting
schema must match the tablespace name for the importingschema. Only
sysdba can create a new tablespace
if that is necessary, so for practical reasons it makes sense for
sysdba to check the
tablespaces on both databases, create the directory objects, and
grant to the ordinary user DMUSER
the
permission to write to and read from the directory objects.
Suppose that the folder C:\ODMr_Files
exists. Then the following sequence gives DMUSER permission
to create a directory object linked to C:\ODMR_Files to hold
the files associated with exporting a model.
C:\>sqlplus sys/oracle as sysdba
SQL*Plus: Release 10.2.0.1.0
Connected to:
Oracle Database 10g Enterprise Edition Release
10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> GRANT CREATE ANY DIRECTORY TO DMUSER;
Grant succeeded.
Now DMUSER can create the needed directory.
C:\>sqlplus dmuser/dmuser
SQL*Plus: Release 10.2.0.1.0
Oracle Database 10g Enterprise Edition Release
10.2.0.1.0 – Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE OR REPLACE DIRECTORY model_dump AS ‘C:\ODMr
_Files’;
Directory created.
Now sysdba grants
directory access to DMUSER.
C:\>sqlplus sys/oracle as sysdba
SQL*Plus: Release 10.2.0.1.0
Connected to:
Oracle Database 10g Enterprise Edition Release
10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> GRANT READ, WRITE ON DIRECTORY model_dump TO
dmuser;
Grant succeeded.
Now, suppose that DMUSER has
created a Decision Treemodel
MINING_DATA_B4762_DT and wishes to export the model to another
Oracle 10g R2 database. On the SQLPLUS
command line, DMUSER must execute the EXPORT_MODEL function with
arguments specifying the name of the dumpfile to be created, the
directory object, and the model name,
SQL> EXECUTE DBMS_DATA_MINING.EXPORT_MODEL
('DT3.DMP', 'model_dump', 'name =
''MINING_DATA_B4762_DT''');
PL/SQL procedure successfully completed.
SQL>
Note:
The model name is surrounded by two single quotes,
not double quotes.
Now copy the file DT3.DMP to the existing directory
NEW_DIR on the destination server.
Importing the model to a new Oracle database
Assuming that sysdba has granted permission to the
user on the destination database to create and read from the
directory NEW_DIR, the model can be imported and used by executing
the following command.
SQL> exec dbms_data_mining.import_model('DT3.DMP',
'NEW_DIR');
Since no model name is entered as an argument, all
models in the dumpfile are imported.
The model is now available for use in the new
environment. Recall that in order to apply the model to data, the
data must be prepared in exactly the same way that the source data
for building the model was prepared.