-
Notifications
You must be signed in to change notification settings - Fork 0
/
wine_mlp.m
48 lines (31 loc) · 919 Bytes
/
wine_mlp.m
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
%% MLP - dataset: Wine Dataset
%author = @leilamr
close all;
clear all;
clc
[inputs, targets] = wine_dataset;
%% create neural network
hiddenLayerSize = 4;
trainFcn = 'trainlm';
net = patternnet(hiddenLayerSize, trainFcn);
% set neural network
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
net.trainParam.epochs = 1000;
net.trainParam.max_fail = 500;
net.trainParam.min_grad = 0.000000000000001;
net.trainParam.lr = 0.1;
net.layers{1}.transferFcn='logsig';
net.layers{2}.transferFcn='purelin';
%% train network
[net, tr] = train(net,inputs,targets);
%% test the Network
outputs = net(inputs);
e = gsubtract(targets,outputs);
performance = perform(net,targets,outputs);
tind = vec2ind(targets);
yind = vec2ind(outputs);
percentErrors = sum(tind ~= yind)/numel(tind);
acc = 100 * (1 - percentErrors);
fprintf('Accuracy = %.3f%% \n', acc);