predict
predict labels using discriminant analysis classification model
Description
[[
也返回:标签
,,,,分数
,,,,成本
] =预测(MDL
,,,,X
)
一个矩阵classification scores (
分数
)在dicating the likelihood that a label comes from a particular class. For discriminant analysis, scores are后概率。一个矩阵expected classification cost((
成本
)。对于每个观察X
,,,,the predicted class label corresponds to the minimum expected classification cost among all classes.
输入参数
MDL
-判别分析分类模型
ClassificationDiscriminant
模型对象|CompactClassificationDiscriminant
模型对象
判别分析分类模型,指定为ClassificationDiscriminant
orCompactClassificationDiscriminant
返回的模型对象fitcdiscr
。
X
-预测数据要分类
数字矩阵|桌子
预测数据要分类,指定为数字矩阵或表。
每一行的X
corresponds to one observation, and each column corresponds to one variable. All predictor variables inX
一定是numeric vectors.
For a numeric matrix, the variables that compose the columns of
X
必须具有与训练的预测变量相同的顺序MDL
。对于表格:
predict
除了字符矢量的细胞金宝app阵列以外,不支持多列变量和细胞阵列。如果您训练有素
MDL
使用表(例如,tbl
),,,,then all predictor variables inX
必须具有与受过训练的变量名称和数据类型相同的变量MDL
((stored inmdl.predictictornames
)。However, the column order ofX
不需要对应于tbl
。tbl
andX
can contain additional variables (response variables, observation weights, etc.), butpredict
忽略它们。如果您训练有素
MDL
using a numeric matrix, then the predictor names inmdl.predictictornames
以及相应的预测变量名称X
必须相同。要在培训期间指定预测指标,请参见predictorNames
名称值对参数fitcdiscr
。X
can contain additional variables (response variables, observation weights, etc.), butpredict
忽略它们。
Data Types:桌子
|double
|single
Output Arguments
成本
-Expected classification costs
数字矩阵
Expected classification costs,作为大小的矩阵返回n
-by-k
。n
是the number of observations (rows) inX
, 和k
是the number of classes (inmdl.classnames
)。费用(i,j)
是the cost of classifying row一世
ofX
作为课堂j
在mdl.classnames
。
Examples
predict Class Labels Using Discriminant Analysis Model
加载Fisher的虹膜数据集。Determine the sample size.
加载渔业n =尺寸(MES,1);
partition the data into training and test sets. Hold out 10% of the data for testing.
RNG(1);% For reproducibilitycvp = cvpartition(n,'Holdout',0.1);idxtrn =训练(CVP);%培训套件指数idxtest = test(CVP);% Test set indices
Store the training data in a table.
tbltrn = array2table(MES(idxtrn,:));tbltrn.y =物种(idxtrn);
train a discriminant analysis model using the training set and default options.
mdl = fitcdiscr(tbltrn,'y');
预测测试集的标签。你训练了MDL
using a table of data, but you can predict labels using a matrix.
标签s = predict(Mdl,meas(idxTest,:));
Construct a confusion matrix for the test set.
confusionchart(species(idxTest),labels);
MDL
misclassifies one versicolor iris as virginica in the test set.
plot Class Posterior Probability Regions
加载Fisher的虹膜数据集。考虑仅使用花瓣长度和宽度训练。
加载渔业x = meas(:,3:4);
使用整个数据集训练二次判别分析模型。
MDL=fitcdiscr((X,,,,species,'DiscrimType',,,,'quadratic');
定义观察到的预测器空间中的值网格。预测网格中每个实例的后验概率。
xmax = max(x);xmin = min(x);d = 0.01;[x1grid,x2grid] = meshgrid(xmin(1):d:xmax(1),xmin(2):d:xmax(2));[〜,得分] =预测(mdl,[x1grid(:),x2grid(:)]);mdl.classnames
ans =3x1单元阵列{'setosa'} {'versicolor'} {'virginica'}
分数
是类后验概率的矩阵。这些列对应于mdl.classnames
。例如,得分(J,1)
是the posterior probability that observationj
是a setosa iris.
为网格中的每个观察结果绘制versicolor分类的后验概率,并绘制训练数据。
数字;CONTOURF(X1Grid,X2Grid,Reshape(得分(:,2),size(x1Grid,1),size(x1Grid,2)));h =配色栏;卡克西斯([0 1]);结肠jet; holdongScatter(x(::,1),x(:,2),物种,,,'mcy',,,,'.x+');axistighttitle(“ versicolor的后概率”);抓住离开
后概率区域暴露了决策边界的一部分。
更多关于
posterior Probability
the posterior probability that a pointz属于阶级j是先前概率和多元正常密度的乘积。多元正常的密度函数,平均μjand covariance Σj在某个时候z是
where 是the determinant of Σk, 和 是反矩阵。
Letp((k)represent the prior probability of classk。then the posterior probability that an observationX是of classk是
wherep((X)是a normalization constant, the sum overkofp((X|k)p((k)。
prior Probability
先前的概率是三个选择之一:
'uniform'
-the prior probability of classk
是one over the total number of classes.'empirical'
-the prior probability of classk
是the number of training samples of classk
除以培训样本的总数。习惯 - 课程的先验概率
k
是thek
元素事先的
vector. Seefitcdiscr
。
After creating a classification model (MDL
)您可以使用点表示法设置先验:
mdl.prior = v;
wherev
是代表每个元素发生频率的正元素的向量。设置新的先验时,您无需重新训练分类器。
Cost
在Cost。
predicted Class Label
predict
分类以最大程度地减少预期的分类成本:
where
是the predicted classification.
k是类的数量。
是theposterior probabilityof classkfor observationX。
是the成本of classifying an observation asy当它的真实班级是k。
Extended Capabilities
高阵列
用比在内存中拟合更多的行的数组计算。
此功能完全支持高阵列。金宝app有关更多信息,请参阅高阵列((MATLAB).
C/C++ Code Generation
使用MATLAB®CODER™生成C和C ++代码。
Usage notes and limitations:
利用
saveLearnerForCoder
,,,,加载LearnerForCoder
, 和codegen
为生成代码predict
function. Save a trained model by usingsaveLearnerForCoder
。Define an entry-point function that loads the saved model by using加载LearnerForCoder
and calls thepredict
function. Then usecodegen
为入口点函数生成代码。this table contains notes about the arguments of
predict
。Arguments not included in this table are fully supported.Argument 注释和限制 MDL
For the usage notes and limitations of the model object, see代码生成of the
CompactClassificationDiscriminant
object.X
必须是单精度或双重矩阵,并且可以是可变大小的。但是,在
X
一定是numel(Mdl.PredictorNames)
。Rows and columns must correspond to observations and predictors, respectively.
有关更多信息,请参阅Introduction to Code Generation。
在R2011b中引入
Open Example
A modified version of this example exists on your system. Do you want to open this version instead?
MATLAB Command
您单击了与此MATLAB命令相对应的链接:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择一个网站
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:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
美洲
- AméricaLatina((Español)
- 加拿大((English)
- 美国((English)
欧洲
- netherlands((English)
- norway((English)
- Österreich(德意志)
- 葡萄牙((English)
- Sweden((English)
- 瑞士
- United Kingdom((English)