文档

predict

predict labels using discriminant analysis classification model

Description

标签=预测(MDL,,,,Xreturns a vector of predicted class labels for the predictor data in the table or matrixX,基于训练有素的判别分析分类模型MDL

[[标签,,,,分数,,,,成本] =预测(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.

输入参数

expand all

判别分析分类模型,指定为ClassificationDiscriminantorCompactClassificationDiscriminant返回的模型对象fitcdiscr

预测数据要分类,指定为数字矩阵或表。

每一行的Xcorresponds 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 ofX必须具有与训练的预测变量相同的顺序MDL

  • 对于表格:

    • predict除了字符矢量的细胞金宝app阵列以外,不支持多列变量和细胞阵列。

    • 如果您训练有素MDL使用表(例如,tbl),,,,then all predictor variables inX必须具有与受过训练的变量名称和数据类型相同的变量MDL((stored inmdl.predictictornames)。However, the column order ofX不需要对应于tbltblandXcan contain additional variables (response variables, observation weights, etc.), butpredict忽略它们。

    • 如果您训练有素MDLusing a numeric matrix, then the predictor names inmdl.predictictornames以及相应的预测变量名称X必须相同。要在培训期间指定预测指标,请参见predictorNames名称值对参数fitcdiscrXcan contain additional variables (response variables, observation weights, etc.), butpredict忽略它们。

Data Types:桌子|double|single

Output Arguments

expand all

预测的类标签,返回categorical or character array, logical or numeric vector, or cell array of character vectors.

标签

  • Is the same data type as the observed class labels (y)训练MDL(该软件将字符串阵列视为字符向量的单元格数组。)

  • 长度等于行的数量X

predicted class后概率,返回数字矩阵of sizen-by-kn是the number of observations (rows) inX, 和k是the number of classes (inmdl.classnames)。分数((一世,,,,j)是the posterior probability that observation一世X是of classjmdl.classnames

Expected classification costs,作为大小的矩阵返回n-by-kn是the number of observations (rows) inX, 和k是the number of classes (inmdl.classnames)。费用(i,j)是the cost of classifying row一世ofX作为课堂jmdl.classnames

Examples

expand all

加载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');

预测测试集的标签。你训练了MDLusing 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);

MDLmisclassifies one versicolor iris as virginica in the test set.

加载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的后概率”);抓住离开

后概率区域暴露了决策边界的一部分。

更多关于

expand all

Extended Capabilities

在R2011b中引入