ClassificationPartitionedNeuralNetwork
Description
ClassificationPartitionedNeuralNetwork is a set of classification
neural network models trained on cross-validated folds. You can estimate the quality of the
classification by using one or more kfold functions: kfoldPredict, kfoldLoss, kfoldMargin, kfoldEdge, and kfoldfun.
Each kfold function uses models trained on training-fold (in-fold)
observations to predict the response for validation-fold (out-of-fold) observations. For
example, when you use kfoldPredict with a k-fold
cross-validated model, the software estimates a response for every observation using the model
trained without that observation. For more information, see Partitioned Models.
Creation
You can create a ClassificationPartitionedNeuralNetwork object in two ways:
Properties
Cross-Validation Properties
This property is read-only.
Cross-validated model name, returned as 'NeuralNetwork'.
Data Types: char
This property is read-only.
Number of folds in the cross-validated model, returned as a positive integer.
Data Types: double
This property is read-only.
Cross-validation parameter values, returned as an
EnsembleParams object. The parameter values correspond to the
values of the name-value arguments used to cross-validate the neural network model.
ModelParameters does not contain estimated parameters.
You can access the properties of ModelParameters using dot
notation.
This property is read-only.
Partition used in the cross-validation, returned as a cvpartition object.
This property is read-only.
Compact models trained on the cross-validation folds, returned as a cell array of
CompactClassificationNeuralNetwork model objects.
Trained has k cells, where
k is the number of folds.
Data Types: cell
Other Classification Properties
This property is read-only.
Categorical predictor
indices, returned as a vector of positive integers. CategoricalPredictors
contains index values indicating that the corresponding predictors are categorical. The index
values are between 1 and p, where p is the number of
predictors used to train the model. If none of the predictors are categorical, then this
property is empty ([]).
Data Types: double
This property is read-only.
Unique class labels used in training, returned as a categorical or
character array, logical or numeric vector, or cell array of
character vectors. ClassNames has the same
data type as the class labels Y.
(The software treats string arrays as cell arrays of character
vectors.)
ClassNames also determines the class
order.
Data Types: categorical | char | logical | single | double | cell
Misclassification costs, specified as a square numeric matrix.
Cost has K rows and columns, where
K is the number of classes.
Cost(i,j) is the cost of classifying a point into class
j if its true class is i. The order of the
rows and columns of Cost corresponds to the order of the classes
in ClassNames.
You can change the cost matrix using dot notation. For example, for a
cross-validated model CVMdl and a cost matrix
costMatrix, you can
specify:
CVMdl.Cost = costMatrix;
Data Types: double
This property is read-only.
Number of observations in the training data stored in X and
Y, returned as a positive
integer scalar.
Data Types: double
This property is read-only.
Predictor variable names, returned as a cell array of character vectors. The order of the
elements in PredictorNames corresponds to the order in which the
predictor names appear in the training data.
Data Types: cell
This property is read-only.
Prior probabilities for each class, returned as a numeric vector. The order of the
elements of Prior corresponds to the order of the classes in
ClassNames.
Data Types: double
This property is read-only.
Response variable name, returned as a character vector.
Data Types: char
Score transformation function, specified as a character vector, string scalar, or function
handle. ScoreTransform represents a built-in transformation function or a
function handle for transforming predicted classification scores.
To change the score transformation function to function, for example, use dot notation.
For a built-in function, enter a character vector or string scalar.
Mdl.ScoreTransform = "function";
This table lists the values for the available built-in functions.
Value Description "doublelogit"1/(1 + e–2x) "invlogit"log(x / (1 – x)) "ismax"Sets the score for the class with the largest score to 1, and sets the scores for all other classes to 0 "logit"1/(1 + e–x) "none"or"identity"x (no transformation) "sign"–1 for x < 0
0 for x = 0
1 for x > 0"symmetric"2x – 1 "symmetricismax"Sets the score for the class with the largest score to 1, and sets the scores for all other classes to –1 "symmetriclogit"2/(1 + e–x) – 1 For a MATLAB® function or a function that you define, enter its function handle.
Mdl.ScoreTransform = @function;
functionmust accept a matrix (the original scores) and return a matrix of the same size (the transformed scores).
Data Types: char | string | function_handle
This property is read-only.
Observation weights, returned as an n-by-1 numeric vector,
where n is the number of observations (NumObservations).
Data Types: double
This property is read-only.
Unstandardized predictors used to cross-validate the model, returned as a numeric
matrix or a table. X retains its original orientation, with
observations in rows or columns depending on the value of the
ObservationsIn name-value argument in the call to
fitcnet.
Data Types: single | double | table
This property is read-only.
Class labels used to cross-validate the model, returned as a numeric vector,
logical vector, character array, cell array of character vectors, or categorical
array. Each row of Y represents the classification of the
corresponding observation in X.
Data Types: single | double | logical | char | cell | categorical
Object Functions
gather | Gather properties of Statistics and Machine Learning Toolbox object from GPU |
kfoldEdge | Classification edge for cross-validated classification model |
kfoldLoss | Classification loss for cross-validated classification model |
kfoldMargin | Classification margins for cross-validated classification model |
kfoldPredict | Classify observations in cross-validated classification model |
kfoldfun | Cross-validate function for classification |
Examples
Cross-validate a neural network classifier using the default 10-fold cross-validation.
Load the ionosphere data set, which includes radar signal data. X contains the predictor data, and Y is the response variable, whose values represent either good ("g") or bad ("b") radar signals.
load ionosphereTrain a neural network classifier using the fitcnet function. Specify 35 outputs for the first fully connected layer and 20 outputs for the second fully connected layer.
Mdl = fitcnet(X,Y,LayerSizes=[35 20])
Mdl =
ClassificationNeuralNetwork
ResponseName: 'Y'
CategoricalPredictors: []
ClassNames: {'b' 'g'}
ScoreTransform: 'none'
NumObservations: 351
LayerSizes: [35 20]
Activations: 'relu'
OutputLayerActivation: 'softmax'
Solver: 'LBFGS'
ConvergenceInfo: [1×1 struct]
TrainingHistory: [72×7 table]
Properties, Methods
Mdl is a trained ClassificationNeuralNetwork model object.
Cross-validate the classifier using 10-fold cross-validation. During cross-validation, the software completes these steps:
Randomly partition the data into 10 sets (folds) of equal size.
For each set, reserve the set as validation data, and train a neural network classifier on the other nine sets.
Store the 10 trained models in a 10-by-1 cell vector in the
Trainedproperty of the cross-validated model object.
CVMdl = crossval(Mdl)
CVMdl =
ClassificationPartitionedNeuralNetwork
CrossValidatedModel: 'NeuralNetwork'
PredictorNames: {'x1' 'x2' 'x3' 'x4' 'x5' 'x6' 'x7' 'x8' 'x9' 'x10' 'x11' 'x12' 'x13' 'x14' 'x15' 'x16' 'x17' 'x18' 'x19' 'x20' 'x21' 'x22' 'x23' 'x24' 'x25' 'x26' 'x27' 'x28' 'x29' 'x30' 'x31' 'x32' 'x33' 'x34'}
ResponseName: 'Y'
NumObservations: 351
KFold: 10
Partition: [1×1 cvpartition]
ClassNames: {'b' 'g'}
ScoreTransform: 'none'
Properties, Methods
CVMdl is a ClassificationPartitionedNeuralNetwork object.
Display the first model in CVMdl.Trained.
FirstModel = CVMdl.Trained{1}FirstModel =
CompactClassificationNeuralNetwork
LayerSizes: [35 20]
Activations: 'relu'
OutputLayerActivation: 'softmax'
Properties, Methods
FirstModel is the first of the 10 trained models contained in CVMdl. The trained models are all CompactClassificationNeuralNetwork objects.
After creating a cross-validated neural network model object, you can estimate the generalized classification error by passing the model to kfoldLoss.
Algorithms
You can create partitioned models by using k-fold cross-validation, holdout validation, leave-one-out cross-validation, or resubstitution.
k-fold cross-validation — The software divides the observations into
KFolddisjoint folds, each of which has approximately the same number of observations. The software trainsKFoldmodels (Trained), and each model is trained onKFold– 1 of the folds. When you usekfoldPredict, each model predicts the response values for the remaining fold.Holdout validation — The software partitions the observations into a training set and a validation set. The software trains one model (
Trained) using the training set. When you usekfoldPredict, the model predicts the response values for the validation set.Leave-one-out cross-validation — The software creates
NumObservationsfolds, where each observation is a fold. The software trainsNumObservationsmodels (Trained), and each model is trained onNumObservations– 1 of the folds. When you usekfoldPredict, each model predicts the response for the remaining fold (observation).Resubstitution — The software does not partition the data. The software trains one model (
Trained) on the entire data set. When you usekfoldPredict, the model predicts the response values for all observations.
Extended Capabilities
The object functions of a ClassificationPartitionedNeuralNetwork model
fully support GPU arrays.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2026a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)