• No results found

Displaying fitted models

In this work, fitted models are visualised on two-dimensional and three-dimensional sections only. Figure 3.3 shows how the basic section visualisations in condvis dis- play fitted models. Regression models (top row of Figure 3.3) are represented as curves or surfaces (either a perspective view, or a colour map), and classifiers are visualised as colour maps (bottom row of Figure 3.3). Two broad types of regression models are considered: classical models, where the fitted model ( ˆf) is determined by fixed parameter values (maximum likelihood estimates, for example), and Bayesian models, where ˆf is determined up to probability distributions on its parameters.

3.3.1 Classifiers

For classification problems, we follow Hastie et al. (2009) in visualising a classifier as assigning colours to regions of the predictor space. When considering binary class probabilities, we can proceed as for a regression model below. If we are interested in multi-class probabilities (see Section 6.3), we can produce a grid of barcharts similar to embedded plots (Grolemund and Wickham, 2015) instead of the basic colour map in Figure 3.3.

resp onse quan titativ e 2 3 4 5 10 15 20 25 30 Conditional expectation wt mpg ●● ● svm 0 1 10 15 20 25 30 Conditional expectation vs mpg ● ● ● ● ● ● svm wt 2 3 4 5 hp 100 150 200 250 300 mpg 15 20 25 30 Conditional expectation ● ● ● 10 15 20 25 30 mpg Conditional expectation carb vs ● ● ● ● ● ● ● ● ● ● ● ● 1 2 3 4 6 8 0 1 10 15 20 25 30 mpg 2 3 4 5 Conditional expectation wt vs ● ● ● ● ● ● ● ● ● ● 0 1 10 15 20 25 30 mpg categorical 2 3 4 5 50 100 150 200 250 300 Conditional expectation wt hp ● ●● ● ● ● ● cyl 4 6 8 Conditional expectation carb vs ● ● ● ● ●● ● ● ● ● ● ● ● 1 2 3 4 6 8 0 1 cyl 4 6 8 2 3 4 5 Conditional expectation wt carb ● ● ● ● ● ● ● ● 1 2 3 4 6 8 cyl 4 6 8

1 quant 1 cat 2 quant 2 cat 1 quant 1 cat

section predictors

Figure 3.3: Displaying a fitted model on a section (quant = quantitative, cat = categorical). For a categorical response, and a single section predictor, it is preferable to consider the class probability as a quantitative response, or add an extra section predictor.

3.3.2 Classical regression models

The ˆf from classical regression models can be interpreted as a surface in data space, and so we can easily show its intersection with the section we have chosen. We then simply have the task of visualising the function ˆf(xS,xC) wherexS are seen as free

parameters which can vary across their range andxC are fixed parameters defining the section. This is the same approach to visualising sections through fitted models as for ICE plots (see Section 2.5).

3.3.3 Bayesian regression models

Bayesian models, on the other hand, provide a probability distribution for the ex- pected response via a probability distribution on the parameters of the model. To visualise such models, a simple approach is to evaluate the posterior distribution on a grid, calculating the median (or some other measure of central tendency) each time, and finally visualise a surface joining these medians together.

If Markov Chain Monte Carlo (MCMC) is used when the posterior is difficult to calculate, we have a sample of predictive functions, and can produce a sample from the posterior ofE[y |x] on the section. One option here is to show all of the sampled predictive functions on the section and use transparency to give an impression of the probability distribution ofE[y |x] on the section. For implementation reasons, this option has not been explored in this work as transparency is not possible on some of the graphics devices needed for interactivity inR. Instead, for each of our points on the grid of xS values, we have a sample of ˆf. We calculate quantiles of

each of these samples and then show the median values, as well as percentiles for 2.5% and 97.5%. In this way, we can visualise a Bayesian model as a surface in data space, and therefore in the same manner as in Section 3.3.2. See Section 6.6 for an example of visualising sections through a Bayesian model.

3.3.4 Implementation: predict

In R, predictions for a fitted model are often calculated using a method for the generic predict function. This can be a function which accepts as arguments the fitted model object and a new data frame of observations, and returns the predictions of the model. See, for example, the documentation for?predict.lminR.

Incondvis, fitted models are evaluated on the section using the generic predict method. Thepredict methods are not implemented in a consistent manner across all model objects inR. Sometimes, there is simply no predict method, for example, when the parameters of a Bayesian model are sampled using external software. Model objects of class S4 can be very specific about their inputs, and fail with an error when unnecessary arguments are supplied, instead of ignoring them as in the less strict S3 paradigm. The best way to deal with these situations is to make an S3 object which acts as a wrapper to the fitted model object, and behaves like an

(a) (b)

Figure 3.4: Visualising a section. (a) Visualising a 2 predictor model, and taking a section athp = 200. (b) Visualising the section through model at hp= 200. There are no observed data points on this section.

object of classlmin terms of input and output of itspredictmethod. Examples of this kind of wrapper object can be seen in the examples in Chapter 6.

Related documents