MATLAB: How to train and simulate a Newff or nntool

nntool newff neuralnetwork

Hi, I have been stuck with this problem, if someone could help please..
I have a input data of (512×240) and a target data of (512×1). This data is basically divided by two classes I want to classify. My target is this matrix consisted of 1 or 0. I am using 50% of data for training and other 50% (I mean 512×240) as my test input. Which will have the size output of (1×512). Of course the training and test input/output are different. I can train my network using the code bellow:
net = newff(input,target,10,{'tansig'},'trainrp','learngd','msereg'); net = train(net,input,target); simulacao = sim(net,test);
Is this code providing me a neural network which will have two different inputs? I mean the way I set up my data is going to provide my the output I need? I need the network to classify my inputs as 1 or 0. This code performance its been pretty poor as I added up more data and trained with a 50-50% rate.

Best Answer

  • How to train and simulate a Newff or nntool
    Asked by Mariana about 12 hours ago
    Hi, I have been stuck with this problem, if someone could help please..
    I have a input data of (512x240) and a target data of (512x1).
    This data is basically divided by two classes I want to classify.
    My target is this matrix consisted of 1 or 0. I am using 50% of data for training and other 50% (I mean 512x240) as my test input. Which will have the size output of (1x512). Of course the training and test input/output are different. I can train my network using the code bellow:
    GEH0. Ending semicolons have been purposely omitted for display
    purposes
    1. Transpose so that
    [ I0 N ] = size(input) % [ 240 512 ]
    [ O0 N ] = size(target0) % [ 1 512 ]
    2. Transform target0 into a 2x512 matrix with {0,1} unit vector
    columns that correspond to class indices 1 and 2
    target = full(ind2vec(target0+1))
    trueclassindices = vec2ind(target)
    [ O N ] = size(target) % [ 2 512 ]
    3. Reduce the input size from I0 = 240 to something more
    practical. 512 points in 240 dimensions is averaging only ~2
    points per dimension. At least 10 to 30 points per dimension
    would be preferable
    4. I prefer PLSREGRESS over PCA(which ignores targets) for
    classifier dimensionality reduction. I don't think the linear
    coefficient STEPWISEFIT works well for unit vector target
    classifiers.
    help PLSREGRESS
    doc PLSREGRESS
    [ I N ] = size(input) % [ ? 512 ]
    5. If you don't have the current classifier PATTERNNET,
    use the obsolete NEWPR (NEWFF modified for classification)
    help NEWPR
    doc NEWPR
    6. The first time through use as many defaults as possible
    (e.g., 0.7/0.15/0.15 ratios for training, validation and testing).
    The main parameter to size is the number of hidden nodes. A reasonable upperbound to avoid overfitting is
    Ntrn = N -2*round(0.15*N) % 358
    Ntrneq = Ntrn*O % 716
    Hub = (Ntrn*O-O)/(I+O+1) % 2.9 ==> NEED to reduce I
    7. If the net is overfit MUST consider
    a. VALIDATION STOPPING
    b. BAYESIAN REGULARIZATION
    8. For regression, MSEREG and TRAINBR would be
    considered w.r.t. 7b. However, I have never used either for
    classification.
    % net = newff(input,target,10,{'tansig'},'trainrp','learngd','msereg'); % net = train(net,input,target); simulacao = sim(net,test); % Is this code providing me a neural network which will have two % different inputs? I mean the way I set up my data is going to % provide my the output I need? I need the network to classify my % inputs as 1 or 0. This code performance its been pretty poor as % I added up more data and trained with a 50-50% rate.
    CONSIDER DOCUMENTATION EXAMPLE
    Class indices are 1 and 2
    Remove ending semicolons to investigate details
    close all, clear all, clc
    help newpr
    [ x t ] = simpleclass_dataset;
    [ I N ] = size(x) % [ 2 1000 ]
    [O N ] = size(t) % [ 4 1000 ]
    trueclassind = vec2ind(t);
    vart1 = mean(var(t',1))% 0.18723 MSE Reference
    H = 2 % From x-plane plot
    net = newpr( x, t, H);
    rng('default')
    [ net tr y e ] = train( net, x , t);
    % y= net( x ); e = t - y;
    outclassind = vec2ind(y);
    err = outclassind~=trueclassind;
    Nerr = sum(err) % 0

    PctErr = 100*Nerr/N % 0
    plotperform
    plotconfusion
    Hope this helps.
    *Thank you for formally accepting my answer*
    Greg