# nLinearCoeffs

Number of nonzero linear coefficients

## Syntax

ncoeffs = nLinearCoeffs(obj)
ncoeffs = nLinearCoeffs(obj,delta)

## Description

ncoeffs = nLinearCoeffs(obj) returns the number of nonzero linear coefficients in the linear discriminant model obj.

ncoeffs = nLinearCoeffs(obj,delta) returns the number of nonzero linear coefficients for threshold parameter delta.

## Input Arguments

 obj Discriminant analysis classifier, produced using fitcdiscr. delta Scalar or vector value of the Delta parameter. See Gamma and Delta.

## Output Arguments

 ncoeffs Nonnegative integer, the number of nonzero coefficients in the discriminant analysis model obj. If you call nLinearCoeffs with a delta argument, ncoeffs is the number of nonzero linear coefficients for threshold parameter delta. If delta is a vector, ncoeffs is a vector with the same number of elements. If obj is a quadratic discriminant model, ncoeffs is the number of predictors in obj.

## Examples

expand all

Find the number of nonzero coefficients in a discriminant analysis classifier for various Delta values.

Create a discriminant analysis classifier from the fishseriris data.

obj = fitcdiscr(meas,species);

Find the number of nonzero coefficients in obj.

ncoeffs = nLinearCoeffs(obj)
ncoeffs = 4

Find the number of nonzero coefficients for delta = 1, 2, 4, and 8.

delta = [1 2 4 8];
ncoeffs = nLinearCoeffs(obj,delta)
ncoeffs = 4×1

4
4
3
0

The DeltaPredictor property gives the values of delta where the number of nonzero coefficients changes.

ncoeffs2 = nLinearCoeffs(obj,obj.DeltaPredictor)
ncoeffs2 = 4×1

4
3
1
2