Using exported classifer model

2 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2016-6-10
To match that code, your T needs to be a table with column named "column_1" (the same as the predictor name)
  1 个评论
KB
KB 2016-6-10
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Classification Learner App 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by