Load the fisheriris sample data set.
The column vector species contains three iris flower species: setosa, versicolor, and virginica. The matrix meas contains four types of measurements for the flowers: the length and width of sepals and petals in centimeters.
Fit a multinomial regression model using the measurements as the predictor data and the iris species as the response data.
mdl is a multinomial regression model object that contains the results of fitting a nominal multinomial regression model to the data.
Use the rand function to generate new predictor data by adding uniformly distributed random noise to the measurements data.
Each row of measNew corresponds to predictor data for a unique data point.
Generate random response values sampled from the multinomial distributions generated by passing measNew to the fitted model.
speciesPred = 150×1 cell
{'versicolor'}
{'setosa' }
{'setosa' }
{'setosa' }
{'setosa' }
{'versicolor'}
{'setosa' }
{'versicolor'}
{'setosa' }
{'setosa' }
{'setosa' }
{'setosa' }
{'setosa' }
{'setosa' }
{'setosa' }
{'versicolor'}
{'setosa' }
{'versicolor'}
{'setosa' }
{'versicolor'}
{'setosa' }
{'versicolor'}
{'setosa' }
{'setosa' }
{'setosa' }
{'setosa' }
{'versicolor'}
{'setosa' }
{'setosa' }
{'versicolor'}
⋮
Display the original response data.
species = 150×1 cell
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
{'setosa'}
⋮
The outputs for speciesPred and species show that the majority of the randomly generated responses in speciesPred match the original response labels in species. The difference between measNew and meas contributes to the difference between speciesPred and species, as does the random nature of sampling the speciesPred values from the multinomial distributions associated with the predictor data.