label = predict(obj,X)
[label,score] = predict(obj,X)
[label,score,cost] = predict(obj,X)
Matrix where each row represents an observation, and each column represents a predictor. The number of columns in X must equal the number of predictors in obj.
Vector of class labels of the same type as the response data used in training obj. Each entry of labels corresponds to a predicted class label for the corresponding row of X; see Predicted Class Label.
Numeric matrix of size N-by-K, where N is the number of observations (rows) in X, and K is the number of classes (in obj.ClassNames). score(i,j) is the posterior probability that row i of X is of class j; see Posterior Probability.
Matrix of expected costs of size N-by-K. cost(i,j) is the cost of classifying row i of X as class j. See Cost.
The posterior probability that a point z belongs to class j is the product of the prior probability and the multivariate normal density. The density function of the multivariate normal with mean μj and covariance Σj at a point z is
where is the determinant of Σk, and is the inverse matrix.
Let P(k) represent the prior probability of class k. Then the posterior probability that an observation x is of class k is
where P(x) is a normalization constant, the sum over k of P(x|k)P(k).
The prior probability is one of three choices:
'uniform' — The prior probability of class k is one over the total number of classes.
'empirical' — The prior probability of class k is the number of training samples of class k divided by the total number of training samples.
Custom — The prior probability of class k is the kth element of the prior vector. See fitcdiscr.
After creating a classifier obj, you can set the prior using dot notation:
obj.Prior = v;
where v is a vector of positive elements representing the frequency with which each element occurs. You do not need to retrain the classifier when you set a new prior.
The matrix of expected costs per observation is defined in Cost.
predict classifies so as to minimize the expected classification cost:
Examine predictions for a few rows in the Fisher iris data:
load fisheriris obj = fitcdiscr(meas,species); X = meas(99:102,:); % take four rows [label score cost] = predict(obj,X) label = 'versicolor' 'versicolor' 'virginica' 'virginica' score = 0.0000 1.0000 0.0000 0.0000 0.9999 0.0001 0.0000 0.0000 1.0000 0.0000 0.0011 0.9989 cost = 1.0000 0.0000 1.0000 1.0000 0.0001 0.9999 1.0000 1.0000 0.0000 1.0000 0.9989 0.0011