Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
TARGETS FOR NEURAL NETWORK

Subject: TARGETS FOR NEURAL NETWORK

From: Slawomir

Date: 12 May, 2012 14:37:26

Message: 1 of 3

Hello!

Assume, that I have this database INPUT.txt., which is the breast cancer database. http://www.2shared.com/document/l5DYVIVR/INPUT.html

Example of the INPUT.txt

1189286,10,10,8,6,4,5,8,10,1,4
1190394,4,1,1,1,2,3,1,1,1,2
1190485,1,1,1,1,2,1,1,1,1,2
1192325,5,5,5,6,3,10,3,1,1,4
1193091,1,2,2,1,2,1,2,1,1,2
1193210,2,1,1,1,2,1,3,1,1,2
1193683,1,1,2,1,3,1,1,1,1,2

4 - stands for malignant
2 - stands for benign
1193210 - number of sample, irrelevant

There are two values 2 and 4, and I want to classify those classes using neural network.

If I want to classify that classes I need to have 2 outputs eg. T=[T;T];
My idea was to code that target values 4 and 2 into 0 0 and 1 1.
And a few questions:
1. What is the best way to code that target values?
2. What if I will have more than 4 and 2? Lets say that 10 values. How to code it? I guess for 10 values sth like T=[T;T;T;T;T;T;T;T;T;T] will be totally inefficient, because it is easier to calculate weight values for numbers from range 0 - 1 instead of 2 - 4 in this case or even bigger.
I probably need to create class from combination 0 and 1,
1-st: 0 0 0
2-nd: 0 1 0
3-th: 0 1 1
4-th: 1 1 1
5-th: 1 0 0
6-th: 1 0 1
7-th: 0 0 1
8-th: 1 1 0
and so on.


My code:

dane = load('INPUT.txt');
P = dane(:, 2:10)';
T = dane(:, 11)'; % Targets
T = [T;T];
net = newff(P, T, [4 4], {'logsig' 'logsig'});
[net, tr] = train(net, P, T);
S = sim(net, P);
MSE = mse(T - S)
figure, plotconfusion(T,S)


I coded 4 and 2 into 0 and 1 by using this code instead T = [T;T];

c = T./2 - 1; % Creates 0 and 1
T = [c;c];


Any ideas?
Thanks for help!

Subject: TARGETS FOR NEURAL NETWORK

From: Greg Heath

Date: 12 May, 2012 23:26:28

Message: 2 of 3

On May 12, 10:37 am, "Slawomir " <SlawomirBab...@gmail.com> wrote:
> Hello!
>
> Assume, that I have this database INPUT.txt., which is the breast cancer database.http://www.2shared.com/document/l5DYVIVR/INPUT.html
>
> Example of the INPUT.txt
>
> 1189286,10,10,8,6,4,5,8,10,1,4
> 1190394,4,1,1,1,2,3,1,1,1,2
> 1190485,1,1,1,1,2,1,1,1,1,2
> 1192325,5,5,5,6,3,10,3,1,1,4
> 1193091,1,2,2,1,2,1,2,1,1,2
> 1193210,2,1,1,1,2,1,3,1,1,2
> 1193683,1,1,2,1,3,1,1,1,1,2
>
> 4 - stands for malignant
> 2 - stands for benign
> 1193210 - number of sample, irrelevant
>
> There are two values 2 and 4, and I want to classify those classes using neural network.
>
> If I want to classify that classes I need to have 2 outputs eg. T=[T;T];
> My idea was to code that target values 4 and 2 into 0 0 and 1 1.
> And a few questions:
> 1. What is the best way to code that target values?
> 2. What if I will have more than 4 and 2? Lets say that 10 values. How to code it? I guess for 10 values sth like T=[T;T;T;T;T;T;T;T;T;T] will be totally inefficient, because it is easier to calculate weight values for numbers from range 0 - 1 instead of 2 - 4 in this case or even bigger.
> I probably need to create class from combination 0 and 1,
> 1-st: 0 0 0
> 2-nd: 0 1 0
> 3-th: 0 1 1
> 4-th: 1 1 1
> 5-th: 1 0 0
> 6-th: 1 0 1
> 7-th: 0 0 1
> 8-th: 1 1 0
> and so on.
>
> My code:
>
> dane = load('INPUT.txt');
> P = dane(:, 2:10)';
> T = dane(:, 11)';   % Targets
> T = [T;T];
> net = newff(P, T, [4 4], {'logsig' 'logsig'});
> [net, tr] = train(net, P, T);
> S = sim(net, P);
> MSE = mse(T - S)
> figure, plotconfusion(T,S)
>
> I coded 4 and 2 into 0 and 1 by using this code instead T = [T;T];
>
> c = T./2 - 1; % Creates 0 and 1
> T = [c;c];
>
> Any ideas?
> Thanks for help!

Subject: TARGETS FOR NEURAL NETWORK

From: Greg Heath

Date: 13 May, 2012 05:11:18

Message: 3 of 3

On May 12, 10:37 am, "Slawomir " <SlawomirBab...@gmail.com> wrote:
> Hello!
>
> Assume, that I have this database INPUT.txt., which is the breast cancer database.http://www.2shared.com/document/l5DYVIVR/INPUT.html

close all, clear all, clc

load BreastCancer_dataset.txt
whos
x0 = BreastCancer_dataset(:,2:10)';
t0 = BreastCancer_dataset(:,end)';
whos
[ I N ] = size(x0)
[ O N ] = size(t0) % Only need one output for 2 classes

t0(t0==2) = 0; % Convert to probability targets
t0(t0==4) = 1;

stepwise(x0',t0') % inputs 4,5 and 9 are not significant for a
linear model

% For simplicity, ignore possibility of input variable reduction for
NN model
% For c >= 2 classes can use O = c outputs.
% Code output vectors as columns of the c- dimensional unit matrix.
% Use ind2vec to convert from class indices to unit matrix columns
% Outputs are estimates of class posterior probabilities
% Obtain class indices using function vec2ind.

Ntst = ceil(N/6) % For an unbiased error
estimate
Nval = Ntst % For choosing No. of
hidden nodes, H
Ntrn = N-(Nval+Ntst) % For determining weights given H
Neq = Ntrn*O % No. of Training equations

% Find H by trial and error. Use val set to choose
% Nw = (I+1)*H+(H+1)*O No. of unknown weights for I-H-O node
topology

Hub = floor((Neq-O)/(I+O+1)) % Upperbound for H if Neq >=Nw

% Require H < Hub, if not using validation set stopping or
regularization (msereg)
% Desire H << Hub for mitigation of noise and measurement errors

For sample code, search using

heath newff Ntrials

> My code:
>
> dane = load('INPUT.txt');
> P = dane(:, 2:10)';
> T = dane(:, 11)'; % Targets
> T = [T;T];

No. See above

> net = newff(P, T, [4 4], {'logsig' 'logsig'});

No.
Only need 1 hidden layer
Use tansig for hidden nodes
Find H by trial and error

net = newff(P, T, H, {'tansig' 'logsig'});

> [net, tr] = train(net, P, T);
> S = sim(net, P);
> MSE = mse(T - S)
> figure, plotconfusion(T,S)
>
> I coded 4 and 2 into 0 and 1 by using this code instead T = [T;T];
>
> c = T./2 - 1; % Creates 0 and 1
> T = [c;c];

No. Either

 Tnew = c % One dimensional O = 1

or

Tnew = [ c ; 1-c ] % Two dimensional O = 2


Hope this helps.

Greg

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us