Hi everyone,
I wonder if anyone out there can assist. I am learning to use the classification learner app in Matlab2015a. I generated some 'toy' data with 2 columns, choosing column 1 as predictor and column 2 as the response. 1 trained the CosineKNN classifer on this toy data and exported my model. I would now like to make some predictions using some new data.
When I exported the model I got the following messages
Variables have been created in the base workspace.To use the exported classifier 'trainedClassifier' to make predictions on new data, T, use yfit = predict(trainedClassifier, T{:,trainedClassifier.PredictorNames})If your new data contains any integer variables, then preprocess the data to doubles like this: X = table2array(varfun(@double, T(:,trainedClassifier.PredictorNames))); yfit = predict(trainedClassifier, X)
So I ran the code below on a vector called toytestdata and got the following
Error using numelBad subscripting index.Error in toyscript (line 9)yfit = predict(trainedClassifier, T{:,trainedClassifier.PredictorNames})
Here is my code
% code
% Variables have been created in the base workspace.
% To use the exported classifier 'trainedClassifier' to make predictions on new data, T, use
% yfit = predict(trainedClassifier, T{:,trainedClassifier.PredictorNames})
%
% If your new data contains any integer variables, then preprocess the data to doubles like this:
% X = table2array(varfun(@double, T(:,trainedClassifier.PredictorNames)));
% yfit = predict(trainedClassifier, X)
T=toytestdata yfit = predict(trainedClassifier, T{:,trainedClassifier.PredictorNames}) end
My questions are
1.Is my input data in the right format.?
2. Do I need to change the PredictorNames field in my code. I note that this is listed as column_1 in the model…..is there any way to change this..
3. Do I need to do anything else to get this running.
Thanks very much for your help. I attached a few pictures which may assist..
Have a nice weekend
Kevin
Best Answer