Reputation: 1562
I am using PCA
before feeding the training set into a neural network. It reduces 13 features down to 8 and trains over 2200 training sets. The MAPE I get with this is close to 2.5 - 2.6 %.
If I train the raw data with simple feedforwardnet
, I get a lower error of 2.1%.
I am suffering from a similar situation in a different problem, where I have close to 50000 training sets where PCA gives 2.5% error and simple ANN gives me ~2% MAPE. What is the reason behind this? Is this a normal occurrence? Can you give me any way by which I can reduce the error? I am trying to forecast the electric load demand on the basis of weather and previous load data.
EDIT: (Added Scree Plot )
Upvotes: 2
Views: 755
Reputation: 1960
I had the same problem as you back a few Months ago but with SVMs instead of NNs. So the reason why you're getting such poor results is because you haven't normalized your data before feeding it into the PCA function. You can do this using Matlab's mapminmax function. Since mapminmax noramlizes the rows, you need to do a transpose of the input and output as follows.
[normX,PS] = mapminmax( X' );
normX = normX';
max( normX ) % Returns 1
min( normX ) % Returns -1
To plot the scree plot, you can use this code.
[C,~,~,~,explained] = pca( normX );
figure; plot( explained );
This is the Scree plot. You can probably keep the first 5 components of your data.
After you perform the minmax mapping, you can feed it into your NN as follows. This assumes you want to keep PC 1-5.
trainX = normX * C(:,1:5);
Now if you ever need to transform your noramlized data back to
returnedX = mapminmax( 'reverse', normX', PS );
returned = returnedX';
Collectively your code should be as follows
% Normalize Data
[normX,PS] = mapminmax( X' );
normX = normX';
max( normX ) % Returns 1
min( normX ) % Returns -1
% Perform PCA
[C,~,~,~,explained] = pca( normX );
figure; plot( explained );
% Transform Data
trainX = normX * C(:,1:5);
EDIT: Performance The code I used to test performance is below.
clear all
load input
load output
% Normalize Data
[normX,PS] = mapminmax( X' );
normX = normX';
max( normX ) % Returns 1
min( normX ) % Returns -1
% Perform PCA
[C,~,~,~,explained] = pca( normX );
figure; plot( explained );
% Transform Data
trainX1 = normX(1:1826,:) * C(:,1:5);
trainX2 = X(1:1826,:);
trainY = dailyPeakLoad(1:1826);
testX1 = normX(1827:end,:) * C(:,1:5);
testX2 = X(1827:end,:);
testY = dailyPeakLoad(1827:end);
netFeb = newfit(trainX1', trainY', 35);
netFeb.performFcn = 'mae';
netFeb = trainlm(netFeb, trainX1', trainY');
forecastLoadFeb = sim(netFeb, testX1')';
errFeb = testY - forecastLoadFeb;
errpct = abs(errFeb)./testY*100;
MAPEFeb = mean(errpct(~isinf(errpct)));
netFeb2 = newfit(trainX2', trainY', 35);
netFeb2.performFcn = 'mae';
netFeb2 = trainlm(netFeb2, trainX2', trainY');
forecastLoadFeb2 = sim(netFeb2, testX2')';
errFeb2 = testY - forecastLoadFeb2;
errpct2 = abs(errFeb2)./testY*100;
MAPEFeb2 = mean(errpct(~isinf(errpct2)));
The trained NN are here. This is the one with PCA. This is the one without PCA.
Note that performance is different because of initial values and number of iterations.
Upvotes: 2