我为组织中的员工提供了一个数据集,我需要将其分为三类:
我在Matlab中编写了以下代码,并使用了fitcknn
,但收到了以下错误消息:
Error using classreg.learning.FullClassificationRegressionModel.prepareDataCR (line 192)
X must be a numeric matrix.
Error in classreg.learning.classif.FullClassificationModel.prepareData (line 487)
classreg.learning.FullClassificationRegressionModel.prepareDataCR(...
Error in ClassificationKNN.prepareData (line 878)
prepareData@classreg.learning.classif.FullClassificationModel(X,Y,varargin{:},'OrdinalIsCategorical',true);
Error in classreg.learning.FitTemplate/fit (line 213)
this.PrepareData(X,Y,this.BaseFitObjectArgs{:});
Error in ClassificationKNN.fit (line 863)
this = fit(temp,X,Y);
Error in fitcknn (line 261)
this = ClassificationKNN.fit(X,Y,RemainingArgs{:});
Error in WhiteHouse (line 11)
MDL = fitcknn (B,G,'NumNeighbors',5,'standardize',1);
请帮助我看看代码中缺少什么。
%Training Data
B= [ "" "Employee" 50000 "Per Annum" "Assistant" ; "" "Employee" 100000 "Per Annum" "Director" ; "" "" 150000 "Per Annum" "Deputy" ] ;
% Labels
G = [ "Normal" ; "Important" ; "Critical" ] ;
%SampleData
A = ["Brundage" "Employee" 103000 "Per Annum" "SPECIAL" ; "Buffa Nicole" "Employee" 80000 "Per Annum" "DEPUTY DIRECTOR OF CABINET AFFAIRS" ] ;
MDL = fitcknn (B,G,'NumNeighbors',5,'standardize',1);
class = predict (MDL,A)
disp ('Result:') ;
disp (class) ;
答案 0 :(得分:0)
如错误消息中所述,该参数无效。
您的B
变量是一个包含数字和文本数据的单元格。
应该只能是数字,不能是单元格数组。
请参考文档中的示例。 https://www.mathworks.com/help/stats/fitcknn.html#bt6d3vt-2