In the featureContribution function (in the R
package rfFC
), what should we interpret if all the scores for all the features are negative? For example, if there were 7 features and after running the featureContribution
function we got feature values as:
fc = c(-0.031544542, -0.064272583, -0.02307187, -0.000213402, -0.040743263,
-0.042137713, -0.080828973)
Then what is the final interpretation? Is it something like all the features are not contributing to the prediction for this data point?
The github code for the package can be found here.
Please find a reproducible example to work with below
# # randomForest - For random forest model
library(randomForest)
# # rfFc - For feature contribution
library(rfFC)
set.seed(294056)
# # Read input data
df = read.csv("https://raw.githubusercontent.com/kartheekpnsn/MyScripts/master/Files/input.csv")
# # Remove this column
df = df[-8]
# # Remove status column
df$Status = NULL
# # Master data 1-7 columns and Anomaly column
mydf = cbind(df[,1:7], df["Anomaly"])
rm(df)
# # Make Anomaly column as factor
mydf[,8] = as.factor(mydf[,8])
# # Change the name of Anomaly column to Status (not necessary)
colnames(mydf)[8] = "Status"
# # X: predictors
X <- mydf[, 1:(ncol(mydf) - 1)]
# # target: class
target <- mydf[,"Status"]
# # Build the model
rF_Model <- randomForest(x=X, y=as.factor(as.character(target)), ntree=500, importance=TRUE, keep.inbag=TRUE, replace=FALSE)
li <- getLocalIncrements(rF_Model,X)
fc<-featureContributions(rF_Model, li, X)
fc = as.data.frame(fc)
# # Data where the fc score is all negative
output = cbind(fc[apply(fc, 1, function(x) all(x < 0)),], mydf[apply(fc, 1, function(x) all(x < 0)),])
print(fc[apply(fc, 1, function(x) all(x < 0)),])
print(output)