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
# # rfFc - For feature contribution


# # 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"])
# # 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)),])
  • $\begingroup$ It would help if you could add some more context here, such as a reproducible example for people to work with. $\endgroup$ Commented Jun 8, 2016 at 19:09
  • $\begingroup$ (To whom it may concern, note that how to interpret statistical output is generally on topic here.) $\endgroup$ Commented Jun 8, 2016 at 19:10
  • $\begingroup$ Thanks @gung. I have added an example in the question (edited). $\endgroup$ Commented Jun 9, 2016 at 5:47
  • $\begingroup$ Please paste the reproducible example into your question. We want this thread to remain valuable even if the link goes dead. $\endgroup$ Commented Jun 9, 2016 at 12:26
  • $\begingroup$ @KartheekPalepu is there anyway to still download this package? $\endgroup$
    – RTrain3K
    Commented Oct 24, 2019 at 1:33

1 Answer 1


Unlike in the variable importance measures, feature contributions are computed separately for each instance/record and provide detailed information about relationships between variables and the predicted value: the extent and the kind of influence (positive/negative) of a given variable.

For more reference please see Interpreting random forest models using a feature contribution method

The paper can be also found in the describtion of the function from the linked package in the question post.

  • $\begingroup$ So accordingly should we be considering the absolute value instead of considering the signed value as the Feature Contribution score? $\endgroup$ Commented Jun 8, 2016 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.