CompactClassificationNeuralNetwork - Compact neural network model for classification - MATLAB (original) (raw)

Compact neural network model for classification

Since R2021a

Description

CompactClassificationNeuralNetwork is a compact version of aClassificationNeuralNetwork model object. The compact model does not include the data used for training the classifier. Therefore, you cannot perform some tasks, such as cross-validation, using the compact model. Use a compact model for tasks such as predicting the labels of new data.

Properties

expand all

Neural Network Properties

This property is read-only.

Sizes of the fully connected layers in the neural network model.

The property value depends on the method used to fit the model.

Data Types: single | double

This property is read-only.

Learned layer weights for the fully connected layers.

The property value depends on the method used to fit the model.

Data Types: cell

This property is read-only.

Learned layer biases for the fully connected layers.

The property value depends on the method used to fit the model.

Data Types: cell

This property is read-only.

Activation functions for the fully connected layers of the neural network model.

The property value depends on the method used to fit the model.

If Activations is a character vector or a cell array of character vectors, then the values are from this table.

Value Description
"relu" Rectified linear unit (ReLU) function — Performs a threshold operation on each element of the input, where any value less than zero is set to zero, that is, f(x)={x,x≥00,x<0
"tanh" Hyperbolic tangent (tanh) function — Applies the tanh function to each input element
"sigmoid" Sigmoid function — Performs the following operation on each input element: f(x)=11+e−x
"none" Identity function — Returns each input element without performing any transformation, that is, f(x) = x

Data Types: char | cell

This property is read-only.

Activation function for the final fully connected layer.

The property value depends on the method used to fit the model.

Data Properties

This property is read-only.

Predictor variable names, returned as a cell array of character vectors. The order of the elements of PredictorNames corresponds to the order in which the predictor names appear in the training data.

Data Types: cell

This property is read-only.

Categorical predictor indices, returned as a vector of positive integers. Assuming that the predictor data contains observations in rows, CategoricalPredictors contains index values corresponding to the columns of the predictor data that contain categorical predictors. If none of the predictors are categorical, then this property is empty ([]).

Data Types: double

This property is read-only.

Expanded predictor names, returned as a cell array of character vectors. If the model uses encoding for categorical variables, thenExpandedPredictorNames includes the names that describe the expanded variables. Otherwise, ExpandedPredictorNames is the same as PredictorNames.

Data Types: cell

This property is read-only.

Unique class names used in training, returned as a numeric vector, categorical vector, logical vector, character array, or cell array of character vectors.ClassNames has the same data type as the class labels in the response variable used to train the model. (The software treats string arrays as cell arrays of character vectors.) ClassNames also determines the class order.

Data Types: single | double | categorical | logical | char | cell

Since R2023b

This property is read-only.

Predictor means, returned as a numeric vector. If you set Standardize to1 or true when you train the neural network model, then the length of theMu vector is equal to the number of expanded predictors (seeExpandedPredictorNames). The vector contains 0 values for dummy variables corresponding to expanded categorical predictors.

If you set Standardize to 0 or false when you train the neural network model, then the Mu value is an empty vector ([]).

Data Types: double

This property is read-only.

Response variable name, returned as a character vector.

Data Types: char

Since R2023b

This property is read-only.

Predictor standard deviations, returned as a numeric vector. If you setStandardize to 1 or true when you train the neural network model, then the length of theSigma vector is equal to the number of expanded predictors (seeExpandedPredictorNames). The vector contains1 values for dummy variables corresponding to expanded categorical predictors.

If you set Standardize to 0 or false when you train the neural network model, then the Sigma value is an empty vector ([]).

Data Types: double

Other Classification Properties

Misclassification cost, returned as a numeric square matrix, whereCost(i,j) is the cost of classifying a point into classj if its true class is i. The cost matrix always has this form: Cost(i,j) = 1 if i ~= j, and Cost(i,j) = 0 if i = j. The rows correspond to the true class and the columns correspond to the predicted class. The order of the rows and columns of Cost corresponds to the order of the classes in ClassNames.

The software uses the Cost value for prediction, but not training. You can change the Cost property value of the trained model by using dot notation.

Data Types: double

This property is read-only.

Prior class probabilities, returned as a numeric vector. The order of the elements of Prior corresponds to the elements ofClassNames.

Data Types: double

Data Types: char | function_handle

Object Functions

expand all

dlnetwork (Deep Learning Toolbox) Deep learning neural network
edge Classification edge for neural network classifier
loss Classification loss for neural network classifier
margin Classification margins for neural network classifier
predict Classify observations using neural network classifier
compareHoldout Compare accuracies of two classification models using new data
testckfold Compare accuracies of two classification models by repeated cross-validation
gather Gather properties of Statistics and Machine Learning Toolbox object from GPU

Examples

collapse all

Reduce the size of a full neural network classifier by removing the training data from the model. You can use a compact model to improve memory efficiency.

Load the patients data set. Create a table from the data set. Each row corresponds to one patient, and each column corresponds to a diagnostic variable. Use the Smoker variable as the response variable, and the rest of the variables as predictors.

load patients tbl = table(Diastolic,Systolic,Gender,Height,Weight,Age,Smoker);

Train a neural network classifier using the data. Specify the Smoker column of tbl as the response variable. Specify to standardize the numeric predictors.

Mdl = fitcnet(tbl,"Smoker","Standardize",true)

Mdl = ClassificationNeuralNetwork PredictorNames: {'Diastolic' 'Systolic' 'Gender' 'Height' 'Weight' 'Age'} ResponseName: 'Smoker' CategoricalPredictors: 3 ClassNames: [0 1] ScoreTransform: 'none' NumObservations: 100 LayerSizes: 10 Activations: 'relu' OutputLayerActivation: 'softmax' Solver: 'LBFGS' ConvergenceInfo: [1×1 struct] TrainingHistory: [36×7 table]

Properties, Methods

Mdl is a full ClassificationNeuralNetwork model object.

Reduce the size of the model by using compact.

compactMdl = compact(Mdl)

compactMdl = CompactClassificationNeuralNetwork LayerSizes: 10 Activations: 'relu' OutputLayerActivation: 'softmax'

Properties, Methods

compactMdl is a CompactClassificationNeuralNetwork model object. compactMdl contains fewer properties than the full model Mdl.

Display the amount of memory used by each neural network model.

Name Size Bytes Class Attributes

Mdl 1x1 18777 ClassificationNeuralNetwork
compactMdl 1x1 6528 classreg.learning.classif.CompactClassificationNeuralNetwork

The full model is larger than the compact model.

Extended Capabilities

expand all

Usage notes and limitations:

For more information, see Introduction to Code Generation.

Usage notes and limitations:

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced in R2021a

expand all

You can fit a CompactClassificationNeuralNetwork object with GPU arrays by using fitcnet to fit aClassificationNeuralNetwork object to gpuArray data, and then passing the object to compact. MostCompactClassificationNeuralNetwork object functions now support GPU array input arguments so that the functions can execute on a GPU. The object functions that do not support GPU array inputs are lime and shapley.

Convert a CompactClassificationNeuralNetwork object to a dlnetwork (Deep Learning Toolbox) object using the dlnetwork function. Usedlnetwork objects to make further edits and customize the underlying neural network of a CompactClassificationNeuralNetwork object and retrain it using the trainnet (Deep Learning Toolbox) function or a custom training loop.

Neural network models include Mu and Sigma properties that contain the means and standard deviations, respectively, used to standardize the predictors before training. The properties are empty when the fitting function does not perform any standardization.

fitcnet supports misclassification costs and prior probabilities for neural network classifiers. Specify the Cost andPrior name-value arguments when you create a model. Alternatively, you can specify misclassification costs after training a model by using dot notation to change the Cost property value of the model.