Using exported classifer model

1 visualización (últimos 30 días)
KB
KB el 10 de Jun. de 2016
Comentada: KB el 10 de Jun. de 2016
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 numel
Bad 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

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Jun. de 2016
To match that code, your T needs to be a table with column named "column_1" (the same as the predictor name)
  1 comentario
KB
KB el 10 de Jun. de 2016
Thanks very much Walter. All working and my headache is beginning to dissipate now I have stopped banging my head against a brick wall.... much obliged and enjoy your weekend. Kevin

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by