フィルターのクリア

To Create mean squared error as a Function handle for input to genetic algorithm

3 ビュー (過去 30 日間)
I am working on machine learning algorithms namely svm, knn, nb, elm etc. I wish to use ga for feature selection. The input matrix is of size 1250*36 where 36 is the number of features. I have the predicted output and original target matrix. The size of the matrix is 1250*5 since the number of classes is 5. Now I need to give the input matrix as input and to find the mean squared error between the predicted output and target matrix which should be formed as function handle which will be given as input to ga(genetic algorithm). Please help and share your points. Thanks in advance

採用された回答

David Hill
David Hill 2022 年 4 月 12 日
targetMatrix=50*rand(1250,5);
predictedOutput=50*rand(1250,5);
mse=@(t,p)mean((t-p).^2,'all');
MSE=mse(targetMatrix,predictedOutput);
  1 件のコメント
Little Flower
Little Flower 2022 年 4 月 12 日
編集済み: Little Flower 2022 年 4 月 12 日
Thank you dear David Hill. Now there is no error in giving it as a function handle input. Also I have a doubt on giving input to genetic algorithm. I have used knn in the below program and while running there is no change in the fitness value. Kindly go through my code and check whether it is correct or not. Thanks in advance
mdl_knn= fitcknn(featuresTrain,YTrain,'NumNeighbors',1,'Standardize',1);
fun=@(t,p)mse_fn(mdl_knn,featuresTest,YTest_out);
options = gaoptimset('TolFun', 1e-8,'display','iter');
gg=ga(fun,36,options);
end
function mse_new=mse_fn(mdl_knn,featuresTest,YTest_out)
[YPred_knn,scores]= predict(mdl_knn,featuresTest);
mse_new=mean((scores-YTest_out).^2,'all');
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by