How can i write code on matlab to find the last value in each row contains the target label for that row, and the remaining values are the features. Split the data into 10 approximately equally-sized "folds". ?

 Réponse acceptée

Image Analyst
Image Analyst le 13 Déc 2020

0 votes

Try this:
m = randi(9, 30000, 3); % Sample data.
lastColumn = m(:, end);
targetValue = 5; % Whatever...
% Find where the last column matches our target value.
matches = lastColumn == targetValue;
fprintf('Found %d matches of %d (out of %d) in the last column.\n', ...
sum(matches), size(m, 1), targetValue);
% Extract the matching rows up until but not including the last column.
m2 = m(matches, 1:end-1);
[rows2, columns2] = size(m2)
% Get starting and ending rows to split this up into 10 submatrices.
rStart = round(linspace(1, rows2-rows2/10, 10))
rEnd = [rStart(2:end)-1, rows2]

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by