How to train ANN from PCA results? - neural-network

I have performed PCA to all images of my database so I have different vectors returned from PCA like Egenface mean etc.
My question is Which vector I would use to train my NN in MATLB? And How would I train NN for 5 clases?

Related

SVM Classifications on set of images of digits in Matlab

I have to use SVM classifier on digits dataset. The dataset consists of images of digits 28x28 and a toal of 2000 images.
I tried to use svmtrain but the matlab gave an error that svmtrain has been removed. so now i am using fitcsvm.
My code is as below:
labelData = zeros(2000,1);
for i=1:1000
labelData(i,1)=1;
end
for j=1001:2000
labelData(j,1)=1;
end
SVMStruct =fitcsvm(trainingData,labelData)
%where training data is the set of images of digits.
I need to know how i can predict the outputs of test data using svm? Further is my code correct?
The function that you are looking for is predict. It takes the SVM-object as input followed by a data-matrix and returns the predicted labels.
Make sure that you do not train your model on all data but on a reasonable subset (usually 70%). You can use the cross-validation preparation:
% create cross-validation object
cvp = cvpartition(Lbl,'HoldOut',0.3);
% extract logical vectors for training and testing data
lgTrn = cvp.training;
lgTst = cvp.test;
% train SVM
mdl = fitcsvm(Dat(lgTrn,:),Lbl(lgTrn));
% test / predict SVM
Lbl_prd = predict(mdl,Dat(lgTst,:));
Note that your labeling produces a single vector of ones.
The reason why The Mathworks changed svmtrain to fitcsvm is conciseness. It is now clear whether it is "classification" (fitcsvm) or "regression" (fitrsvm).

Autoencoder in MATLAB

My goal is to train an Autoencoder in Matlab. I am using the Deep Learning Toolbox. I am new to both autoencoders and Matlab, so please bear with me if the question is trivial.
My input datasets is a list of 2000 time series, each with 501 entries for each time component. So my input dataset is stored into an array called inputdata which has dimensions 2000*501.
The autoencoder should reproduce the time series. Thi means the output should be 2000 times a time series of 501 components. So, my understanding is that the input nodes should be 501 and the same should be true for the output nodes.
However, if I do:
hiddenSize = 100;
autoenc = trainAutoencoder(y_sorted,hiddenSize);
to train an autoencoder with 100 nodes in the hidden layer, I think the Autoencoder automatically chooses to have 2000 input nodes. What is the correct way of training this Autoencoder?
Hi I haven't tried to train an autoencoder myself with the Deeplearning toolbox, but as far as i can read here (https://www.mathworks.com/help/deeplearning/ref/trainautoencoder.html?s_tid=doc_ta) your input matrix should have the samples as columns and the features/values of your timeseries in the rows. You can do this easy by transposing your input matrix. In MATLAB this is done by:
inputdata = inputdata.'

How to extract success ratio for knn classifier

I am trying to implement a knn classifier for eigen-faces as a home assignment (matlab).
I have a weights matrix weights extracted from a test matrix and eigen vectors eVectors and a vector of labels train_face_id.
First of is this a correct way to construct the classifier?
%project the test set to the eigenfaces space
projections=eVectors*weights;
%construct the classifier
mdl=fitcknn(weights,train_face_id,'Standardize',1);
Secondly (and this is the main question) I am requested to say "What are the success ratios (for face_id)?". Is that what I get from rloss=resubLoss(mdl);? If not how do I extract the success ratios?

Matlab predict function not working

I am trying to train a linear SVM on a data which has 100 dimensions. I have 80 instances for training. I train the SVM using fitcsvm function in MATLAB and check the function using predict on the training data. When I classify the training data with the SVM all the data points are being classified into only one class.
SVM = fitcsvm(votes,b,'ClassNames',unique(b)');
predict(SVM,votes);
This gives outputs as all 0's which corresponds to 0th class. b contains 1's and 0's indicating the class to which each data point belongs.
The data used, i.e. matrix votes and vector b are given the following link
Make sure you use a non-linear kernel, such as a gaussian kernel and that the parameters of the kernel are tweaked. Just as a starting point:
SVM = fitcsvm(votes,b,'KernelFunction','RBF', 'KernelScale','auto');
bp = predict(SVM,votes);
that said you should split your set in a training set and a testing set, otherwise you risk overfitting

Matlab train svm regressor using LIBVM with a sparse matrix of text

I am conducting a Bag Of Words analysis where I have a sparse matrix of 80x60452, where 1:80 represent the number of days for the text collected on each day. This matrix represents a collection of tweets on a particular day. The experiment is part of a univariate time series prediction and im not to sure how to implement this.
I am using the Text Matrix Generator (TMG) to construct this sparse matrix which will be used agains a response column vector of price observations(80x1).
I will use a the first 70 observations to train the SVM regressor to predict future price instances given a test data set of the remaining instances.
For example:
T = (length(priceData)-10);
trainBoW = BoW(1:T,1:end);
testBoW = BoW(T+1:end,1:end);
trainPrice = pData(1:T);
testPrice = pData(T+1:end);
model = svmtrain(trainBoW, trainPrice,'-c 1 -g 0.07 -b 1');
Running this code throws the error:
Error using svmtrain (line 274)
SVMTRAIN only supports classification into two groups. GROUP contains 62 groups.
How can I train a SVM regression model using libsvm to predict future price instances ?