在 Matlab 中创建用于分类的神经网络

Creating a Neural Network for Classification in Matlab

我正在尝试使用神经网络进行分类,并且编写了以下代码。这是执行训练和分类所需的代码吗?

%n1 to s5(n1=147,n2=205,n3=166,n4=204,n5=167,b1=156,b2=172,b3=153,b4=151,b5=160,r1=133,r2=135,r3=190,r4=143,ru1=133,ru2=153,ru3=154,ru4=137,s1=132,165,130,136,148)
%code: 
T = [n1,n2,n3,n4,n5,b1,b2,b3,b4,b5,r1,r2,r3,r4,r5,ru1,ru2,ru3,ru4,s1,s2,s3,s4,s5];
    x = [0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 4 4 4 4 4];
    net1 = newff(minmax(T),[30 20 1],{'logsig','logsig','purelin'},'trainrp');
    net1.trainParam.show = 1000;
    net1.trainParam.lr = 0.04;
    net1.trainParam.epochs = 7000;
    net1.trainParam.goal = 1e-5;
    [net1] = train(net1,T,x);
     save net1 net1

此外,如果我有更多具有更多特征的样本,那么我应该如何在 T 和 X 中表示它?我如何写 T 和 x?例如:

sample 1 ..... 123 0.56 78 127 .......0 
sample 2 .......127 0.89 56 132 ........0 
sample3...... 134 0.72 65 140...1 
sample4 156 0.55 69 145 .....1 
sample 5 112 0.10 12 120 .......2 
sample 6 123 0.15 24 99 .......2 
sample 7 95 0.32 98 198 ....3 
sample 8 90 0.45 90 200...... 3

是的,您的解决方案似乎是正确的。我应该注意,newff 自 R2010b NNET 7.0 起已过时,最后一次在 R2010a NNET 6.0.4 中使用。现在推荐的功能是feedforwardnet。前馈网络实现应该如下

net = feedforwardnet([30 20]);
net.layers{1:2}.transferFcn = 'logsig'
net.trainParam.show = 1000;
net.trainParam.lr = 0.04;
net.trainParam.epochs = 7000;
net.trainParam.goal = 1e-5;

[net1] = train(net1,T,x);


save net1 net1

我不太确定你想用 minmax 做什么,但这应该是前馈神经网络的基本结构。

要构建 Tx,假设您有以下数据:

[123 0.56 78 127] belongs to class 1
[127 0.89 56 132] belongs to class 1
[134 0.72 65 140] belongs to class 2
[156 0.55 69 145] belongs to class 2
[112 0.10 12 120] belongs to class 3
[123 0.15 24 99] belongs to class 3

您可以按如下方式设置T和x:

T = [ 123 0.56 78 127; 127 0.89 56 132; 134 0.72 65 140; 156 0.55 69 145; 112 0.10 12 120; 123 0.15 24 99];
x = [1; 1; 2; 2; 3; 3];