Hi~
I ran into an error while doing custom regression.
In short, it is a neural network that receives 8 features as input and outputs 1 output.
My code and error are as follows.
clear,clc,close all
data=readmatrix('train.csv');
inputs=data(:,1:8);
targets=data(:,9);
input2=transpose(inputs);
target2=transpose(targets);
inputs2=normalize(input2,2,'range');
layer = mseRegressionLayer('mse');
layers = [
featureInputLayer(8,'Name','in')
fullyConnectedLayer(1,'Name','fc2')
];
lgraph=layerGraph(layers);
dlnet=dlnetwork(lgraph);
iteration = 1;
averageGrad = [];
averageSqGrad = [];
learnRate = 0.005;
gradDecay = 0.75;
sqGradDecay = 0.95;
dlX=dlarray(inputs2);
for it=1:5000
iteration = iteration + 1;
[gradient,loss]=dlfeval(@modelGradients,dlnet,dlX,target2);
[dlX,averageGrad,averageSqGrad] = adamupdate(dlX,gradient,averageGrad,averageSqGrad,iteration,learnRate,gradDecay,sqGradDecay);
if it>=4500 & mod(it,10)==0
disp(it);
end
end
function [gradient,loss]=modelGradients(dlnet,dlx,t)
out=forward(dlnet,dlx);
gradient=dlgradient(loss,dlx);
loss=mean((out-t).^2);
end
Error using dlfeval (line 43)
First input argument must be a formatted dlarray.
Error in untitled3 (line 31)
[gradient,loss]=dlfeval(@modelGradients,dlnet,dlX,target2);
Thank you for reading my question, and I hope someone who has insight will write an answer.

 채택된 답변

Iuliu Ardelean
Iuliu Ardelean 2021년 2월 10일

1 개 추천

Hey, when you call dlX=dlarray(inputs2), you should specify which dimensions are Spatial/Batch/Channel etc.
e.g.
X = randn(3,5);
dlX = dlarray(X,'SC')
SC are space and channel in this case.
Read more here:

댓글 수: 6

jaehong kim
jaehong kim 2021년 2월 11일
oh! I solve the problem Thank you for your answer
jaehong kim
jaehong kim 2021년 2월 14일
Hi
I have additional questions, can you answer me?
Thank you
Iuliu Ardelean
Iuliu Ardelean 2021년 2월 14일
Hi Yeah -- What is the issue?
jaehong kim
jaehong kim 2021년 2월 15일
Hi Thank you Now multivariate regression(y1,y2,y3...y6) is in progress. Regression with one output is good, but regression with more output is not good. To put it simply, W and B's updates are incorrect. Thus, all values of y_pred are equal (---). This is link about it.
https://kr.mathworks.com/matlabcentral/answers/743277-custom-regression-multiple-output?s_tid=srchtitle
Thank you for reading it. Any help is appreciated and welcome.
Iuliu Ardelean
Iuliu Ardelean 2021년 2월 15일
Hey I've read the question and am not sure why this happens. I will try finding what is wrong tomorrow
jaehong kim
jaehong kim 2021년 2월 16일
yes!
Thank you all the time for your hard work.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

태그

질문:

2021년 2월 10일

댓글:

2021년 2월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by