搜索内容 搜索用户

[未答复] 如何使用spxy算法来划分测试与验证集 woshiduoaini222 发表于 2022-1-14 21:21:43
 现在有spxy算法代码，也用excel表格放置好了120个原始样本的单独的光谱数据表a（256*120），以及元素含量真值b表（120*1），想要划分为30个验证集和90个测试集，现有spxy算法代码如下：想问下，我该怎么嵌入数据，需要更改代码哪里？？？最后的结果要如何去看来划分验证集呢？ X=xlsread(''); Y=xlsread(''); dminmax = zeros(1,32); % Initializes the vector of minimum distances M = size(X,1); % Number of rows in X (samples) samples = 1:M; % Auto-scales the Y matrix for i=1:size(Y,2) % For each parameter in Y     yi = Y(:,i);     Y(:,i) = (yi - mean(yi))/std(yi); end D = zeros(M,M); % Initializes the matrix of X distances Dy = zeros(M,M); % Initializes the matrix of Y distances for i=1:M-1     xa = X(i,:);     ya = Y(i,:);     for j = i+1:M       xb = X(j,:);       yb = Y(j,:);       D(i,j) = norm(xa - xb);       Dy(i,j) =  norm(ya - yb);     end end Dmax = max(max(D)); Dymax = max(max(Dy)); D = D/Dmax + Dy/Dymax; % Combines the distances in X and Y [maxD,index_row] = max(D); % maxD = Row vector containing the largest element of each column in D [dummy,index_column] = max(maxD); % index_column = column corresponding to the largest element in matrix D m(1) = index_row(index_column); m(2) = index_column; dminmax(2) = D(m(1),m(2)); for i = 3:32     % This routine determines the distances between each sample still available for selection and each of the samples already selected     pool = setdiff(samples,m); % pool = Samples still available for selection     dmin = zeros(1,M-i+1); % Initializes the vector of minimum distances between each sample in pool and the samples already selected     for j = 1:(M-i+1) % For each sample xa still available for selection         indexa = pool(j); % indexa = index of the j-th sample in pool (still available for selection)         d = zeros(1,i-1); % Initializes the vector of distances between the j-th sample in pool and the samples already selected         for k = 1:(i-1) % The distance with respect to each sample already selected is analyzed             indexb =  m(k); % indexb = index of the k-th sample already selected             if indexa < indexb                 d(k) = D(indexa,indexb);             else                 d(k) = D(indexb,indexa);             end         end         dmin(j) = min(d);     end     % The selected sample corresponds to the largest dmin     [dminmax(i),index] = max(dmin);     m(i) = pool(index); end
 本版积分规则 回帖后跳转到最后一页
热门教程   