Check for missing argument or incorrect argument data type in call to function 'predict'.

2 ビュー (過去 30 日間)
I created my model in two different ways first using fitlm and then fitrlinear. With fitlm everything is okay, but with fitrlinear, when in the last row I use predict(mdl2,Xte), it returns me the error.
I checked all the related documentation but I don' understand why it is wrong.
% Xtr,Ytr = training | Xte,Yte = testing
mdl1 = fitlm(Xtr,Ytr);
mdl2 = fitrlinear(Xtr,Ytr,'KFold',5,'Learner','leastsquares','Regularization','lasso');
ypred1 = predict(mdl1,Xte);
ypred2 = predict(mdl2,Xte);

採用された回答

dpb
dpb 2021 年 4 月 11 日
I've never used fitrlinear (didn't know it existed, in fact), but it appears that it returns a composite object and that the required RegressionLinear object is contained in the .Trained property of the object. If I try your model from just some random data, I see
>> mdl2
mdl2 =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
NumObservations: 10000
KFold: 5
Partition: [1×1 cvpartition]
ResponseTransform: 'none'
Properties, Methods
Properties for class classreg.learning.partition.RegressionPartitionedLinear:
ResponseTransform
CrossValidatedModel
NumObservations
Y
W
PredictorNames
CategoricalPredictors
ResponseName
Trained
KFold
Partition
ModelParameters
>> mdl2.Trained
ans =
5×1 cell array
{1×1 RegressionLinear}
{1×1 RegressionLinear}
{1×1 RegressionLinear}
{1×1 RegressionLinear}
{1×1 RegressionLinear}
>> mdl2.Trained{1}
ans =
RegressionLinear
ResponseName: 'Y'
ResponseTransform: 'none'
Beta: -0.0320
Bias: -0.0072
Lambda: 1.2500e-04
Learner: 'leastsquares'
Properties, Methods
>>
So, because of the 'Kfold,5' factor, there are five linear models; you can evaluate any one of them by
yhat=predict(mdl2.Trained{1},Xtr);
I've not looked into what the 'Kfold,5' option does, either, so I don't know what that really means to have five returned models; I guess you will. :)
I agree the documentation could be a lot more informative about the content and using it it seems...I dug this out from just copying what an example had done by referencing a property; not by description of the functions.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSupport Vector Machine Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by