{ciu}R Documentation

Create CIU object


Sets up a CIU object with the given parameters. CIU objects have "public" and "private" methods. A CIU object is actually a list whose elements are the public functions (methods).

  formula = NULL,
  data = NULL,
  in.min.max.limits = NULL,
  abs.min.max = NULL,
  input.names = NULL,
  output.names = NULL,
  predict.function = NULL,
  vocabulary = NULL



Model/"black-box" object. At least all caret models, the lda model from MASS, and the lm model are supported. Otherwise, the prediction function to be used can be gives as value of the predict.function parameter. A more powerful way is to inherit from FunctionApproximator class and implement an "eval" method.


Formula that describes input versus output values. Only to be used together with data parameter.


The training data used for training the model. If this parameter is provided, a formula MUST be given also. attempts to infer the other parameters from data and formula. i.e. in.min.max.limits, abs.min.max, input.names and output.names. If those parameters are provided, then they override the inferred ones.


matrix with one row per output and two columns, where the first column indicates the minimal value and the second column the maximal value for that input.


data.frame or matrix of min-max values of outputs, one row per output, two columns (min, max).


labels of inputs.


labels of outputs.


can be supplied if a model that is not supported by ciu should be used. As an example, this is the function for lda:

o.predict.function <- function(model, inputs) {
    pred <- predict(model,inputs)

list of labels/concepts to be used when producing explanations and what combination of inputs they correspond to. Example of two intermediate concepts and a higher-level one that combines them: list(intermediate.concept1=c(1,2,3), intermediate.concept2=c(4,5), higher.level.concept=c(1,2,3,4,5))


CIU is implemented in an object-oriented manner, where a CIU object is a list whose methods are made visible as elements of the list. The general way for using CIU objects is to first get a CIU object by calling as e.g. ciu <-, then call ciu.res <- ciu$<method>(...). The methods that can be used in ⁠<method>⁠ are:

"Usage" section is here in "Details" section because Roxygen etc. don't support documentation of functions within functions.


Object of class CIU.

ciu object


Kary Främling Create ciu object from this CIU object.


Främling, K. Contextual Importance and Utility in R: the 'ciu' Package. In: Proceedings of 1st Workshop on Explainable Agency in Artificial Intelligence, at 35th AAAI Conference on Artificial Intelligence. Virtual, Online. February 8-9, 2021. pp. 110-114.

Främling, K. Explainable AI without Interpretable Model. 2020,

Främling, K. Decision Theory Meets Explainable AI. 2020, <>.

Främling, K. Modélisation et apprentissage des préférences par réseaux de neurones pour l'aide à la décision multicritère. 1996, (title translation in English: Learning and Explaining Preferences with Neural Networks for Multiple Criteria Decision Making)


# Explaining the classification of an Iris instance with lda model.
# We use a versicolor (instance 100).
test.ind <- 100
iris_test <- iris[test.ind, 1:4]
iris_train <- iris[-test.ind, 1:4]
iris_lab <- iris[[5]][-test.ind]
model <- lda(iris_train, iris_lab)

# Create CIU object
ciu <-, Species~., iris)

# This can be used with explain method for getting CIU values
# of one or several inputs. Here we get CIU for all three outputs
# with input feature "Petal.Length" that happens to be the most important.
ciu$explain(iris_test, 1)

# It is, however, more convenient to use one of the graphical visualisations.
# Here's one using ggplot.

# LDA creates very sharp class limits, which can also be seen in the CIU
# explanation. We can study what the underlying model looks like using
# plot.ciu and plot.ciu.3D methods. Here is a 3D plot for all three classes
# as a function of Petal Length&Width. Iris #100 (shown as the red dot)
# is on the ridge of the "versicolor" class, which is quite narrow for
# Petal Length&Width.

## Not run: 
# Same thing with a regression task, the Boston Housing data set. Instance
# #370 has the highest valuation (50k$). Model is gbm, which performs
# decently here. Plotting with "standard" bar plot this time.
# Use something like "par(mai=c(0.8,1.2,0.4,0.2))" for seeing Y-axis labels.
gbm <- train(medv ~ ., Boston, method="gbm", trControl=trainControl(method="cv", number=10))
ciu <-, medv~., Boston)

# Same but sort by CI.
ciu$barplot.ciu(Boston[370,1:13], sort = "CI")

# The two other possible plots

# Method "plot" for studying the black-box behavior and CIU one input at a time.

## End(Not run)

[Package ciu version 0.6.0 Index]