Skip to main content
. 2025 Aug 6;25(15):4845. doi: 10.3390/s25154845
Algorithm 1 CNN-based IoT attack detection
Require: Dataset D={X,y}, learning rate η0, batch size B, epochs E, folds K
Ensure: Trained model M, results R
 1: Normalize features: x′=x−xminxmax−xmin,∀x∈X
 2: Initialize model weights W,b∼N(0,σ2)
 3: Initialize result set R←∅
 4: F← Stratified K-fold split on (X,y)
 5: for all (Xtrain,ytrain,Xtest,ytest)∈F do
 6:     (Xtrainres,ytrainres)←SMOTE(Xtrain,ytrain)
 7:     for e=1 to E do
 8:         Shuffle(Xtrainres,ytrainres)
 9:         for all Bi=(XB,yB)⊂(Xtrainres,ytrainres) do
 10:            Z=W∗XB+b
 11:            Z^=Z−μσ2+ϵ
 12:            Z˜=Dropout(Z^,p)
 13:            y^=eZ˜∑eZ˜
 14:            L=−∑i=1Nyilog(y^i)
 15:            W←W−η∂L∂W, b←b−η∂L∂b
 16:         end for
 17:         η←η0×λeE
 18:         Re←Evaluate(M,Xtest,ytest)
 19:         if EarlyStopping(Re) then
 20:              Break
 21:         end if
 22:     end for
 23:     Append Re to R
 24: end for
 25: return M,R