zoukankan      html  css  js  c++  java
  • Matlab probablistic neural network

    matlab中有newpnn这样一个函数,不过help里说的不够清楚,help里是这么说的

    % net = newpnn(P,T,spread) takes two or three arguments, P
    % R-by-Q matrix of Q input vectorsT
    % S-by-Q matrix of Q target class vectors spread
    % Spread of radial basis functions (default = 0.1)

    其实这里 Q 是样本数, S 类数(即训练数据有几个类号), R 特征数

    给一个可以跑得通的样例,用UCI的iris数据,把类号从字符串转为1,2,3,可以在这里下载

    load bezdekIris.data
    [row, col] = size(bezdekIris);
    indices = crossvalind('HoldOut', row, 0.2);%hold out 20% for test, there are 120 logical '1' in indices
    trains = bezdekIris(indices,:);
    tests = bezdekIris(~indices,:);
    % net = newpnn(P,T,spread) takes two or three arguments, P
    % R-by-Q matrix of Q input vectorsT 
    % S-by-Q matrix of Q target class vectors spread 
    % Spread of radial basis functions (default = 0.1)
    % Q is num of samples, S is num of classes, R is num of features
    net = newpnn(trains(:,1:col-1)',ind2vec(trains(:,end)'),0.1);
    %和通常的分类器不一样,这里的第一个参数要求每一列是一个样本,所以要转置,而且第二个参数也不能直接给一个类号的向量
    %要用ind2vec转换一下
    Y = sim(net,tests(:,1:col-1)');
    predictions = vec2ind(Y);
    fprintf('accuracy is %f\n', sum(tests(:,end) == predictions') / size(tests, 1))

    多次运行的结果可能略有不同

  • 相关阅读:
    Solr简介
    儿童节快乐
    添加新的内容分类
    weka
    Junit测试样例
    Linux MySQL单实例源码编译安装5.5.32
    perconatoolkit 工具集安装
    Linux MySQL单实例源码编译安装5.6
    MySQL 开机自启动
    mysql5.6之前需要账号的安全加固
  • 原文地址:https://www.cnblogs.com/fstang/p/3138975.html
Copyright © 2011-2022 走看看