How to extract training set from dataset?

6 vues (au cours des 30 derniers jours)
Gianluca La Manna
Gianluca La Manna le 22 Sep 2015
Hello, I've to extract a training set from my dataset 214x11. How can I do? Please help me!

Réponses (1)

Kirby Fears
Kirby Fears le 22 Sep 2015
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 commentaire
Gianluca La Manna
Gianluca La Manna le 24 Sep 2015

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');

Connectez-vous pour commenter.

Catégories

En savoir plus sur Text Analytics Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by