forked from rtaormina/ELM_MatlabClass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_REGRESSION.m
More file actions
88 lines (72 loc) · 2.76 KB
/
Copy pathexample_REGRESSION.m
File metadata and controls
88 lines (72 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
% EXAMPLE FOR USING ELM_MatlabClass in REGRESSION problems
%
%
% Refer to README.md and ELM_MatlabClass for further details.
%
%
% Copyright 2015 Riccardo Taormina
% riccardo.taormina@gmail.com
%
%
% This file is part of ELM_MatlabClass.
%
% ELM_MatlabClass is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% ELM_MatlabClass is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with ELM_MatlabClass. If not, see <http://www.gnu.org/licenses/>.
%% data loading and preprocessing
% load data (skip 1st row and 1st column, header)
data = csvread('data_akbilgic.csv',1,1);
% get number of inputs and patterns
[nPatterns, nInputs] = size(data);
nInputs = nInputs - 1; % last column is target data
% normalize data between -1 and 1
for i = 1 : (nInputs + 1)
data(:,i) = -1 + 2.*(data(:,i) - min(data(:,i)))./(max(data(:,i)) - min(data(:,i)));
end
% divide datasets
percTraining = 0.6; % 0.6 == use 60% data for training
endTraining = ceil(percTraining * nPatterns);
trainData = data(1:endTraining,:);
validData = data(endTraining+1:end,:);
%% creation and training of ELM model
% defined number of hidden neurons to use
nHidden = 10;
% create ELM for classification
ELM = ELM_MatlabClass('REGRESSION',nInputs,nHidden);
% train ELM on the training dataset
ELM = train(ELM,trainData);
% compute and report accuracy on training dataset
Yhat = predict(ELM,trainData(:,1:end-1));
fprintf('TRAINING RSquared = %3.3f\n',computeR2(trainData(:,end),Yhat));
%% validation of ELM model
Yhat = predict(ELM,validData(:,1:end-1));
fprintf('VALIDATION RSquared = %3.3f\n',computeR2(validData(:,end),Yhat));
%% sensitivity analysis on number of hidden neurons
nHidden = 1:100;
trainR2 = zeros(size(nHidden));
validR2 = zeros(size(nHidden));
for i = 1 : numel(nHidden)
% create ELM for classification
ELM = ELM_MatlabClass('REGRESSION',nInputs,nHidden(i));
% train ELM on the training dataset
ELM = train(ELM,trainData);
Yhat = predict(ELM,trainData(:,1:end-1));
trainR2(i) = computeR2(trainData(:,end),Yhat);
% validation of ELM model
Yhat = predict(ELM,validData(:,1:end-1));
validR2(i) = computeR2(validData(:,end),Yhat);
end
% plot results
plot(nHidden,[trainR2;validR2],'-o');
xlabel('Number of Hidden Neurons');
ylabel('RSquared');
legend({'training','validation'},'Location','southeast')