feval
Predict responses of multinomial regression model using one input for each predictor
Since R2023a
Description
returns the predicted response of Ypred = feval(mdl,X1,X2,...,Xp)mdl to the new input predictors
X1,X2,...,Xp
where p is the number of predictor variables used to fit
mdl.
Examples
Load the fisheriris sample data set.
load fisheririsThe species column vector contains names of three iris flower species: setosa, versicolor, and virginica. The matrix meas contains of four types of measurements for the flowers: the length and width of sepals and petals in centimeters.
Divide the species and measurement data into training and test data by using the cvpartition function. Get the indices of the training data rows by using the training function.
n = length(species);
partition = cvpartition(n,'Holdout',0.05);
idx_train = training(partition);Create training data by using the indices of the training data rows to create a matrix of measurements and a vector of species labels.
meastrain = meas(idx_train,:); speciestrain = species(idx_train,:);
Fit a multinomial regression model using the training data.
MnrModel = fitmnr(meastrain,speciestrain)
MnrModel =
Multinomial regression with nominal responses
Value SE tStat pValue
_______ ______ ________ __________
(Intercept_setosa) 86.305 12.541 6.8817 5.9158e-12
x1_setosa -1.0728 3.5795 -0.29971 0.7644
x2_setosa 23.846 3.1238 7.6336 2.2835e-14
x3_setosa -27.289 3.5009 -7.795 6.4409e-15
x4_setosa -59.58 7.0214 -8.4855 2.1472e-17
(Intercept_versicolor) 42.637 5.2214 8.1659 3.1906e-16
x1_versicolor 2.4652 1.1263 2.1887 0.028619
x2_versicolor 6.6808 1.474 4.5325 5.829e-06
x3_versicolor -9.4292 1.2946 -7.2837 3.248e-13
x4_versicolor -18.286 2.0833 -8.7775 1.671e-18
143 observations, 276 error degrees of freedom
Dispersion: 1
Chi^2-statistic vs. constant model: 302.0378, p-value = 1.5168e-60
MnrModel is a multinomial regression model object that contains the results of fitting a nominal multinomial regression model to the data. By default, virginica is the reference category. The table output shows coefficient statistics for each predictor in meas. The small p-values in the column pValue indicate that all coefficients, at the 95% confidence level, have a statistically significant effect on MnrModel. For example, the p-value for the term x3_setosa indicates that the flower petal length has a statistically significant effect on , where and are category probabilities.
Get the indices of the test data rows, by using the test function. Create test data by using the indices of the test data rows to create a matrix of measurements and a vector of species labels.
idx_test = test(partition); meastest = meas(idx_test,:); speciestest = species(idx_test,:);
Predict the iris species corresponding to the data point in meas that is not included in the training data.
speciespredict = feval(MnrModel,meastest(:,1),meastest(:,2),meastest(:,3),meastest(:,4))
speciespredict = 7×1 cell
{'setosa' }
{'setosa' }
{'setosa' }
{'setosa' }
{'setosa' }
{'versicolor'}
{'versicolor'}
Compare the predicted iris species with the iris species corresponding to the data point in species that is not included in the training data.
speciestest
speciestest = 7×1 cell
{'setosa' }
{'setosa' }
{'setosa' }
{'setosa' }
{'setosa' }
{'versicolor'}
{'versicolor'}
The output shows that the model accurately predicts the iris species of the data points that not included in the training data.
Input Arguments
Multinomial regression model object, specified as a MultinomialRegression model object created with the fitmnr
function.
New predictor input values, specified as p scalars or vectors,
where p is the number of predictor variables used to fit
mdl.
If you pass
X1,X2,...,Xpas a collection of vectors, then each vector must have the same size. Each row of theXicorresponds to an observation.If you pass
X1,X2,...,Xpas a mixture of vectors and scalars,fevalexpands each scalar argument into a constant vector of the same size as the vector arguments.
Example: feval(mdl,[0.1; 0.2],[0.3; 0.4]) evaluates the
two-predictor model mdl at the points p1 = [0.1
0.3] and p2 = [0.2 0.4].
Data Types: single | double
New predictor input values, specified
as a table or an n-by-p matrix, where n
is the number of observations to predict, and p is the number of predictor
variables used to fit mdl.
If
XNewis a table, it must contain all the names of the predictors used to fitmdl. You can find the predictor names in themdl.PredictorNamesproperty.If
XNewis a matrix, it must have the same number of columns as the number of estimated coefficients. You can find the number of estimated coefficients in themdl.NumPredictorsproperty. You can specifyXNewas a matrix only when all names inmdl.PredictorNamesrefer to numeric predictors.
Example: feval(mdl,[6.2 3.4; 5.9 3.0]) evaluates the two-predictor
model mdl at the points p1 = [6.2 3.4] and
p2 = [5.9 3.0].
Data Types: single | double | string | cell | categorical
Output Arguments
Predicted response categories, returned as an n-by-1 categorical
or character array, logical or numeric vector, or cell array of character vectors, where
n is the number of observations to predict.
Ypred has the same data type as
mdl.ClassNames.
Alternative Functionality
Version History
Introduced in R2023a
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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)