getFitted: Extract the fitted data from a model object

Description Usage Arguments Details Value Warning Note

View source: R/OOP_util.R

Description

This function returns the fitted data that the model was built on; that is, if we 'predict' this model using the same data we used to generate the model, we would get this as a result.

Usage

1
getFitted(model)

Arguments

model

is the model for which to extract the fitted data

Details

There is a subtle but significant point about getFitted: it cannot be assumed that predict called with the same data used to generate the model will give the same results as getFitted. In general, when the original data is dropped down through a classifier, it will return the original results. It makes sense: if this is a known data point, then why not return the known class. However, in order to estimate accuracy, most packages will use some type of technique to give a dataset that shows what the model would have return if the datapoint had not been included in the original data. In all cases, getFitted returns this dataset: the one that can be used for error estimation. buildPredict was designed for classifying new data; what it returns when original data is used is dependent on both the type of classifier and the implementation of the package.

Value

a factor variable containing the fitted data

Warning

Note there is a bug in FNN (and possibly the class package) that means that the class reported, and the associated probability is incorrect. As would be expected it's a bit subtle, but it goes as follows:

However, table sorts the input data, so the first class in the list is not necessarily the closest neighbour. Hence, in cases where there is no repetition of classes, that is, all the nearest k neighbours are of unique classes, the function returns the first alpha-numeric class, not the class of the nearest neighbour. I have written getFitted to return the class of the nearest neighbour, but it does not check for repeat classes in the k nearest neighbours. I was not able to do the same for the class package as the C function does not return the indices of nearest neighbours.

Note

The nearest neighbour models in package:FNN and package:class do not enclose their results in a class; when NPEL.Classification builds objects of these types it wraps them in a class so they are recognizable by S3 methods, and attaches the formula and data. Hence, if a model was built directly using these packages the result will not run this function.


henkelstone/NPEL.Classification documentation built on May 17, 2019, 3:42 p.m.