RALG_WEIGHT_FUNCTION

Use the RALG_WEIGHT_FUNCTION setting to specify the name of an existing registered R script that computes the weight or contribution for each attribute in scoring. The specified R script is used in the SQL function PREDICTION_DETAILS to evaluate attribute contribution.

The specified R script defines an R function containing the first input argument for a model object, and the second input argument of an R data.frame for scoring data. When the machine learning function is Classification, Clustering, or Feature Extraction, the target class name, cluster ID, or feature ID is passed by the third input argument to compute the weight for that particular class, cluster, or feature. The script returns a data.frame containing the contributing weight for each attribute in a row. Each row corresponds to that input scoring data.frame.

Example 6-12 Example of RALG_WEIGHT_FUNCTION

This example specifies the name of the R script MY_PREDICT_WEIGHT_SCRIPT that computes the weight or contribution of R model attributes in the model_setting_table.
Begin
insert into model_setting_table values
(dbms_data_mining.ralg_weight_function, 'MY_PREDICT_WEIGHT_SCRIPT');
End;
/
In the Oracle Machine Learning for R script repository, the script MY_PREDICT_WEIGHT_SCRIPT for Regression is registered as:
'function(mod, data) { coef(mod)[-1L]*data }'
In the Oracle Machine Learning for R script repository, the script MY_PREDICT_WEIGHT_SCRIPT for logit Classification is registered as:
'function(mod, dat, clas) {
   v <- predict(mod, newdata=dat, type = "response");
   v0 <- data.frame(v, 1-v); names(v0) <- c("0", "1");
   res <- data.frame(lapply(seq_along(dat),
   function(x, dat) {
   if(is.numeric(dat[[x]])) dat[,x] <- as.numeric(0)
   else dat[,x] <- as.factor(NA);
   vv <- predict(mod, newdata = dat, type = "response");
   vv = data.frame(vv, 1-vv); names(vv) <- c("0", "1");
   v0[[clas]] / vv[[clas]]}, dat = dat));
   names(res) <- names(dat);
   res}'

Related Topics