how to specify the input and target data
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I have a dataset 2310x25 table. I dont know how to specify the input and target data. i'm using the below code for k fold cross validation. 
data= dlmread('data\\inputs1.txt'); %inputs
groups=dlmread('data\\targets1.txt'); % target
Fold=10;
indices = crossvalind('Kfold',length(groups),Fold);
for i =1:Fold
    testy = (indices == i);   
    trainy = (~testy);   
    TestInputData=data(testy,:)'; 
    TrainInputData=data(trainy,:)';
    TestOutputData=groups(testy,:)'; 
    TrainOutputData=groups(trainy,:)';
8 comentarios
Respuestas (1)
  Walter Roberson
      
      
 el 21 de Jun. de 2022
        filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1038775/bankruptcy.csv';
opt = detectImportOptions(filename, 'TrimNonNumeric', true);
data = readmatrix(filename, opt);
data = rmmissing(data);
groups = data(:,end);
data = data(:,1:end-1);
whos groups
[sum(groups==0), sum(groups==1)]
cp = classperf(groups);
Fold=10;
indices = crossvalind('Kfold',length(groups),Fold);
failures = 0;
for i =1:Fold
    test = (indices == i); 
    train = ~test;
    try
        class = classify(data(test,:), data(train,:), groups(train,:));
        classperf(cp, lass, test);
    catch ME
        failures = failures + 1;
        if failures <= 5
            fprintf('failed on iteration %d\n', i);
        else
            break
        end
    end
end
cp
1 comentario
  Walter Roberson
      
      
 el 21 de Jun. de 2022
				The reason for the failure is that you only have 30 entries with class 1, and when you are doing random selection for K-fold purposes, you are ending up with situations where there are no entries for class 1 in the training data.
Ver también
Categorías
				Más información sobre Logical en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

