Estimate the test sample weighted edge (the weighted average of margins) of a generalized additive model.

Load the `fisheriris`

data set. Create `X`

as a numeric matrix that contains two sepal and two petal measurements for versicolor and virginica irises. Create `Y`

as a cell array of character vectors that contains the corresponding iris species.

Suppose that the quality of some measurements is lower because they were measured with older technology. To simulate this effect, add noise to a random subset of 20 measurements.

Randomly partition observations into a training set and a test set with stratification, using the class information in `Y`

. Specify a 30% holdout sample for testing.

Extract the training and test indices.

Specify the training and test data sets.

Train a GAM using the predictors `XTrain`

and class labels `YTrain`

. A recommended practice is to specify the class names.

`Mdl`

is a `ClassificationGAM`

model object.

Estimate the test sample edge.

The average margin is approximately 0.80.

One way to reduce the effect of the noisy measurements is to assign them less weight than the other observations. Define a weight vector that gives the higher quality observations twice the weight of the other observations.

Train a GAM using the predictors `XTrain`

, class labels `YTrain`

, and weights `weightsTrain`

.

Estimate the test sample weighted edge using the weighting scheme.

The weighted average margin is approximately 0.88. This result indicates that, on average, the labels from weighted classifier labels have higher confidence.