trainSoftmaxLayer
Train a softmax layer for classification
Description
Examples
Classify Using Softmax Layer
加载样本数据。
[X,T] = iris_dataset;
X
是虹膜花的四个属性的4x150矩阵:萼片长度,萼片宽度,花瓣长,花瓣宽度。
T
是关联类向量的3x150矩阵,该矩阵定义了每个输入中的三个类中的哪个。每一行都对应一个代表虹膜物种之一(类)的虚拟变量。在每一列中,三个行中的一个1代表特定样本(观察或示例)属于的类。其他类别不属于的其他类别的行中的行中为零。
Train a softmax layer using the sample data.
网= trainSoftmaxLayer(X,T);
使用训练有素的软磁层将观测值分类为三个类之一。
Y = net(X);
Plot the confusion matrix using the targets and the classifications obtained from the softmax layer.
plotconfusion(T,Y);
Input Arguments
X
—Training data
m-by-nmatrix
Training data, specified as anm-by-n矩阵,哪里m是个number of variables in training data, andn是个number of observations (examples). Hence, each column ofX
represents a sample.
Data Types:single
|double
T
—Target data
k-by-nmatrix
Target data, specified as ak-by-n矩阵,哪里k是个number of classes, andn是个number of observations. Each row is a dummy variable representing a particular class. In other words, each column represents a sample, and all entries of a column are zero except for a single one in a row. This single entry indicates the class for that sample.
Data Types:single
|double
Name-Value Arguments
将可选的参数对Name1=Value1,...,NameN=ValueN
, whereName
是个argument name and价值
是个corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and encloseName
in quotes.
Example:“MaxEpochs”,400,'ShowProgressWindow',false
specifies the maximum number of iterations as 400 and hides the training window.
MaxEpochs
—最大训练迭代次数
1000(default) |正整数值
最大训练迭代次数, specified as the comma-separated pair consisting of“MaxEpochs”
和积极的整数价值。
Example:“ maxepochs”,500
Data Types:single
|double
损失功能
—SoftMax层的损失功能
“ Crossentropy”
(default) |'mse'
SoftMax层的损失功能, specified as the comma-separated pair consisting of'LossFunction'
和either“ Crossentropy”
或者'mse'
.
mse
stands for mean squared error function, which is given by:
wheren是个number of training examples, andk是个number of classes.
是个ijth entry of the target matrix,T
, 和
是个ith output from the autoencoder when the input vector isxj.
The cross entropy function is given by:
Example:'LossFunction','mse'
ShowProgressWindow
—Indicator to display the training window
真的
(default) |false
Indicator to display the training window during training, specified as the comma-separated pair consisting of'ShowProgressWindow'
和either真的
或者false
.
Example:'ShowProgressWindow',false
Data Types:logical
TrainingAlgorithm
—培训algorithm
'Trainscg'
(default)
培训algorithm used to train the softmax layer, specified as the comma-separated pair consisting of'TrainingAlgorithm'
和'Trainscg'
,代表缩放的共轭梯度。
Example:'TrainingAlgorithm','trainscg'
Output Arguments
网
— Softmax layer for classification
网络
object
用于分类的SoftMax层,返回为网络
object. The softmax layer,网
, is the same size as the targetT
.
Version History
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(English)
- United States(English)
欧洲
- Belgium(English)
- 丹麦(English)
- Deutschland(德意志)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- 挪威(English)
- Österreich(德意志)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)