How to extract training set from dataset?

4 次查看(过去 30 天)
Hello, I've to extract a training set from my dataset 214x11. How can I do? Please help me!

回答(1 个)

Kirby Fears
Kirby Fears 2015-9-22
If you want to store a subset of your full dataset in memory, like the first 100 rows of the matrix, just use indexing as follows:
% assuming dataset is a 2D array
trainingset=dataset(1:100,:);
This assigns the first 100 rows (for all columns) to the variable "trainingset".
Hope this helps.
  1 个评论
Gianluca La Manna
Gianluca La Manna 2015-9-24

I solved so:

K=7; %7 sono i tipi di vetro
%visualizzazione dei dati
type={'r*','k+','c.','g^', 'b+', 'y*', 'm^'}; %da cambiare colori e simboli
figure('Name', 'Dataset');
for k=1:K
 %restituisce gli indici dove k = al numero dell'ultima colonna del dataset
 I=find(X(:,end)==k);
 plot3(X(I,1),X(I,2),X(I,3),type{k});
 if k==1
     hold on
 end
end
%creazione dell'insieme di apprendimento (training set)
%--------------------------------------
%T è il training set
T={};
%S è il test set
S={};
%pc rappresenta la percentuale di elementi da prendere per ogni classe come
%insieme di apprendimento
pc=0.7;
n=zeros(1,K);
for k=1:K
 %trovo gli indici degli elementi che appartengono alla classe k
 I=find(X(:,end)==k);
 %calcolo il numero di elementi che devo  prendere
 n(k)=round(pc*length(I));
 %prendo n(k) indici di elementi di classe k 
 Ir=randperm(length(I));
 J=I(Ir(1:n(k)));
 %costruisco il training set di classe k 
 T{k}=X(J,1:end-1);
 %trovo gli indici degli elementi da mettere nel test set di calsse k 
 Z=setdiff(I,J);
 S{k}=X(Z,1:end-1);
end
%visualizzo gli elementi del training set
figure('Name', 'Training set');
for k=1:K
 plot3(T{k}(:,1),T{k}(:,2),T{k}(:,3),type{k});
 if k==1
     hold on
 end
end
%fine creazione dell'insieme di apprendimento (training set)
%--------------------------------------
S=cell2mat(S');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Text Analytics Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by