How to train dataset after dimension reduced with autoencoder into a support vector machine?

I am doing a anomaly detection by using stacked autoencoder and one-class svm. The stacked autoencoder is done. The problem is I am unsure of how to use the dimension reduced data after the autoencoder to be trained in the one-class svm?
Here's the code for the stacked autoencoder:
train1 = fullfile(dataFolder, "train_FD001.txt");
[train_data1, train_labels1] = importdata(train1)
% To avoid results from training are different each time
% Explicitly set the random number generator seed
rng('default')
% Specifying the values for the regularizers for the training
%autoenc1 = trainAutoencoder(train_data1,hiddenSize1, ...
autoenc1 = trainAutoencoder(train_data1,100,'MaxEpochs',400,'L2WeightRegularization',1.0, ...
'DecoderTransferFunction','purelin','UseGPU',true)
% Visualize the first autoencoder
view(autoenc1)
% Train the next autoencoder on a set of these vectors extracted from the training data.
% First, you must use the encoder from the trained autoencoder to generate the features.
feat1 = encode(autoenc1,train_data1)
% Specifying the values for the regularizers for the training
autoenc2 = trainAutoencoder(feat1,10,'MaxEpochs',400,...
'DecoderTransferFunction','purelin','UseGPU',true)
% Visualize the second autoencoder
view(autoenc2)
% Train the next autoencoder on a set of these vectors extracted from the training data.
% First, you must use the encoder from the trained autoencoder to generate the features.
feat2 = encode(autoenc2,feat1)
% Specifying the values for the regularizers for the training
autoenc3 = trainAutoencoder(feat2,1,'MaxEpochs',400,...
'DecoderTransferFunction','purelin','UseGPU',true)
% Visualize the third autoencoder
view(autoenc3)
% Train the next autoencoder on a set of these vectors extracted from the training data.
% First, you must use the encoder from the trained autoencoder to generate the features.
feat3 = encode(autoenc3,feat2)
%% Training the final softmax layer
% Train a softmax layer to classify the 50-dimensional feature vectors.
% Unlike the autoencoders, you train the softmax layer in a supervised fashion using labels for the training data.
softnet = trainSoftmaxLayer(feat3,train_data1,'MaxEpochs',400)
% Vizualize the diagram of the softmax layer
view(softnet)
%% Forming a stacked neural network
stackednet = stack(autoenc1,autoenc2,autoenc3,softnet)
% Vizualize the stacked autoencoder
view(stackednet)

Answers (1)

yes,sir,may be use the encoder net to get data low dimension vector as feature,reshape them to feature matrix and label vector,then train it in new svm model

8 Comments

May I know how can I reshape the feature matrix and label vector?
yes,sir,because not see your data,just as use autoencoder before,use origin data by encoder model get low dimension vector,and save it into matrix
fea_vec = encode(your_encoder_model, origin_data);
It results in an error.
I have trained each individual autoencoder and stacked them up into a stacked autoencoder. I believe now my problem is to put my data into the stacked autoencoder for the feature extraction. Then, use the extracted data and put it into the one-class SVM for anomaly detection.
no,sir,should use every model to get feature vector,not use stack net
For that, I believe I've done it in the code.
feat1 = encode(autoenc1,train_data1)
feat2 = encode(autoenc2,feat1)
feat3 = encode(autoenc3,feat2)
So, is it to make feat3 into matrix for the SVM anomaly detection?
yes,sir,may be use feat3 as input,of course,its dimension reduce,may be consider use feat1、feat2

Sign in to comment.

Products

Asked:

on 5 Feb 2022

Commented:

on 9 Feb 2022

Community Treasure Hunt

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

Start Hunting!