4.2.1.2 About In-Database Model Names and Renaming with OML4R Functions
In each OREdm
R model object, the slot name
is the name of the underlying OML4SQL model generated by the OREdm
function.
By default, models built using OREdm
functions are transient objects; they do not persist past the R session in which they were built unless they are explicitly saved in an OML4R datastore or specified with an explicit name when created. OML4SQL models built using Data Miner or SQL, on the other hand, exist until they are explicitly dropped.
R proxy objects can be saved or persisted. Saving a model object generated by an OREdm
function allows it to exist across R sessions and keeps the corresponding in-database machine learning model object in place. While the OREdm
model exists, you can export and import the in-database model object and use it independent of the OML4R object.
You can use the MODEL_NAME
parameter in odm.settings
to explicitly name an in-database model object created in the database. The named in-database model object persists in the database just like those created using Oracle Data Miner or SQL.
Example 4-8 Using MODEL_NAME
parameter to explicitly name in-database model proxy object
This example demonstrates building a Random Forest Model and naming the model using explicit settings. The example uses the MODEL_NAME
parameter in odm.settings
to explicitly name an in-database model object created in the database.
ore.exec("BEGIN DBMS_DATA_MINING.DROP_MODEL(model_name=> 'RF_CLASSIFICATION_MODEL'); EXCEPTION WHEN others THEN null; END;") settings = list(RFOR_MTRY = 3, RFOR_NUM_TREES = 100, RFOR_SAMPLING_RATIO =0.5, model_name="RF_CLASSIFICATION_MODEL") MOD2 <- ore.odmRF(AFFINITY_CARD~., DEMO_DF.train, odm.settings= settings) RES2 <- predict(MOD2, DEMO_DF.test, type= c("class","raw"), norm.votes=TRUE, cache.model=TRUE, supplemental.cols=c("CUST_ID", "AFFINITY_CARD", "BOOKKEEPING_APPLICATION", "BULK_PACK_DISKETTES", "EDUCATION", "FLAT_PANEL_MONITOR", "HOME_THEATER_PACKAGE", "HOUSEHOLD_SIZE", "OCCUPATION", "OS_DOC_SET_KANJI", "PRINTER_SUPPLIES", "YRS_RESIDENCE", "Y_BOX_GAMES"))
In the above code, the model named RF_CLASSIFICATION_MODEL
should be dropped if it already exists because it will throw an exception while we try to build a model with the same name. The In-database Random Forest Classification model named RF_CLASSIFCIATION_MODEL
is built using the specified settings and the model is referenced by the variable MOD2
. The predictions are made using the random forest model MOD2
and the AFFINITY_CARD
as the predictor variable for the test data set DEMO DF test
and the result is stored in the local session in variable RES2
, and the model persists in the database.
While the R model exists or if you have assigned the model a user-specified name, use the OML4SQL model name to access the OML4SQL model through other interfaces, including:
-
Any SQL interface, such as SQL*Plus or SQL Developer
-
Oracle Data Miner
In particular, the model can be used with the OML4SQL prediction functions.
With Oracle Data Miner you can do the following:
-
Get a list of available models
-
Use model views to inspect model details
-
Score appropriately transformed data
Note:
Any explicit user-performed transformations in the R space are not carried over into SQL scoring or Oracle Data Miner. Users can also get a list of models using SQL for inspecting model details or for scoring appropriately transformed data.Parent topic: About Building OML4SQL Models using OML4R