Categories &

Functions List

Class Definition: ClassificationNeuralNetwork

statistics: obj = ClassificationNeuralNetwork (X, Y)
statistics: obj = ClassificationNeuralNetwork (…, name, value)

Create a ClassificationNeuralNetwork class object containing a Neural Network classification model.

obj = ClassificationNeuralNetwork (X, Y) returns a ClassificationNeuralNetwork object, with X as the predictor data and Y containing the class labels of observations in X.

  • X must be a N×P numeric matrix of input data where rows correspond to observations and columns correspond to features or variables. X will be used to train the model.
  • Y is N×1 matrix or cell matrix containing the class labels of corresponding predictor data in X. Y can contain any type of categorical data. Y must have same numbers of rows as X.

obj = ClassificationNeuralNetwork (…, name, value) returns a ClassificationNeuralNetwork object with parameters specified by Name-Value pair arguments. Type help fitcnet for more info.

A ClassificationNeuralNetwork object, obj, stores the labelled training data and various parameters for the Neural Network classification model, which can be accessed in the following fields:

FieldDescription
XUnstandardized predictor data, specified as a numeric matrix. Each column of X represents one predictor (variable), and each row represents one observation.
YClass labels, specified as a logical or numeric vector, or cell array of character vectors. Each value in Y is the observed class label for the corresponding row in X.
NumObservationsNumber of observations used in training the model, specified as a positive integer scalar. This number can be less than the number of rows in the training data because rows containing NaN values are not part of the fit.
RowsUsedRows of the original training data used in fitting the ClassificationNeuralNetwork model, specified as a numerical vector. If you want to use this vector for indexing the training data in X, you have to convert it to a logical vector, i.e X = obj.X(logical (obj.RowsUsed), :);
StandardizeA boolean flag indicating whether the data in X have been standardized prior to training.
SigmaPredictor standard deviations, specified as a numeric vector of the same length as the columns in X. If the predictor variables have not been standardized, then "obj.Sigma" is empty.
MuPredictor means, specified as a numeric vector of the same length as the columns in X. If the predictor variables have not been standardized, then "obj.Mu" is empty.
NumPredictorsThe number of predictors (variables) in X.
PredictorNamesPredictor variable names, specified as a cell array of character vectors. The variable names are in the same order in which they appear in the training data X.
ResponseNameResponse variable name, specified as a character vector.
ClassNamesNames of the classes in the class labels, Y, used for fitting the ClassificationNeuralNetwork model. ClassNames are of the same type as the class labels in Y.
LayerSizesSizes of the fully connected layers in the neural network model, returned as a positive integer vector. The ith element of LayerSizes is the number of outputs in the ith fully connected layer of the neural network model. LayerSizes does not include the size of the final fully connected layer. This layer always has K outputs, where K is the number of classes in Y.
ActivationsA character vector or a cell array of character vector specifying the activation functions used in the hidden layers of the neural network.
OutputLayerActivationA character vector specifying the activation function of the output layer the neural network.
LearningRateA positive scalar value defining the learning rate used by the gradient descend algorithm during training.
IterationLimitA positive scalar value defining the number of epochs for training the model.
DisplayInfoA boolean flag indicating whether to print information during training.
ModelParametersA structure containing the parameters used to train the Neural Network classifier model containing the fields LayerWeights and Activations as generated by the fcnntrain function.
ConvergenceInfoA structure containing the Convergence info of the Neural Network classifier model with the following fields:
FieldsDescription
AccuracyThe prediction accuracy at each iteration during the neural network model’s training process.
TrainingLossThe loss value recorded at each iteration during the neural network model’s training process.
TimeThe cumulative time taken for all iterations, measured in seconds.
SolverSolver used to train the neural network model, returned as ’Gradient Search’.
ScoreTransformA function_handle which is used for transforming the Neural Network prediction score into a posterior probability. By default, it is 'none', in which case the predict and resubPredict methods return the prediction scores.

See also: fitcnet, fcnntrain, fcnnpredict

Source Code: ClassificationNeuralNetwork

Method: compact

ClassificationNeuralNetwork: CVMdl = compact (obj)

Create a CompactClassificationNeuralNetwork object.

CVMdl = compact (obj) creates a compact version of the ClassificationNeuralNetwork object, obj.

See also: fitcnet, ClassificationNeuralNetwork, CompactClassificationNeuralNetwork

Method: crossval

ClassificationNeuralNetwork: CVMdl = crossval (obj)
ClassificationNeuralNetwork: CVMdl = crossval (…, Name, Value)

Cross Validate a Neural Network classification object.

CVMdl = crossval (obj) returns a cross-validated model object, CVMdl, from a trained model, obj, using 10-fold cross-validation by default.

CVMdl = crossval (obj, name, value) specifies additional name-value pair arguments to customize the cross-validation process.

NameValue
"KFold"Specify the number of folds to use in k-fold cross-validation. "KFold", k, where k is an integer greater than 1.
"Holdout"Specify the fraction of the data to hold out for testing. "Holdout", p, where p is a scalar in the range (0,1).
"Leaveout"Specify whether to perform leave-one-out cross-validation. "Leaveout", Value, where Value is ’on’ or ’off’.
"CVPartition"Specify a cvpartition object used for cross-validation. "CVPartition", cv, where isa (cv, "cvpartition") = 1.

See also: fitcnet, ClassificationNeuralNetwork, cvpartition, ClassificationPartitionedModel

Method: predict

ClassificationNeuralNetwork: labels = predict (obj, XC)
ClassificationNeuralNetwork: [labels, scores] = predict (obj, XC)

Classify new data points into categories using the Neural Network classification object.

labels = predict (obj, XC) returns the vector of labels predicted for the corresponding instances in XC, using the trained neural network classification model in obj.

  • obj must be a ClassificationNeuralNetwork class object.
  • X must be an M×P numeric matrix with the same number of predictors P as the corresponding predictors of the trained neural network model in obj.

[labels, scores] = predict (obj, XC also returns scores, which represent the probability of each label belonging to a specific class. For each observation in X, the predicted class label is the one with the highest score among all classes. Alternatively, scores can contain the posterior probabilities if the ScoreTransform has been previously set.

See also: fitcnet, ClassificationNeuralNetwork

Method: resubPredict

ClassificationNeuralNetwork: labels = resubPredict (obj)
ClassificationNeuralNetwork: [labels, scores] = resubPredict (obj)

Classify the training data using the trained Neural Network classification object.

labels = resubPredict (obj) returns the vector of labels predicted for the corresponding instances in the training data, using the predictor data in obj.X and corresponding labels, obj.Y, stored in the Neural Network classification model, obj.

  • obj must be a ClassificationNeuralNetwork class object.

[labels, scores] = resubPredict (obj, XC) also returns scores, which represent the probability of each label belonging to a specific class. For each observation in X, the predicted class label is the one with the highest score among all classes. Alternatively, scores can contain the posterior probabilities if the ScoreTransform has been previously set.

See also: fitcnet, ClassificationNeuralNetwork

Method: savemodel

ClassificationNeuralNetwork: savemodel (obj, filename)

Save a ClassificationNeuralNetwork object.

savemodel (obj, filename) saves a ClassificationNeuralNetwork object into a file defined by filename.

See also: loadmodel, fitcnet, ClassificationNeuralNetwork, cvpartition, ClassificationPartitionedModel