-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_spilt_2.m
More file actions
48 lines (38 loc) · 1.66 KB
/
Copy pathdata_spilt_2.m
File metadata and controls
48 lines (38 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% Split Data to Test and Train from 3 separate feature_table_WL%d_WInc%d.mat
% WL100,WInc 20 | WL150,WInc 30 | WL200, WInc40 |
% Define paths will be need to changed for feature type base
load('feature_table.mat');
% Define paths
data_path = 'Data';
train_folder = fullfile(data_path, 'train');
test_folder = fullfile(data_path, 'test');
% Create train and test folders if they don't exist
if ~exist(train_folder, 'dir')
mkdir(train_folder);
end
if ~exist(test_folder, 'dir')
mkdir(test_folder);
end
% Define the ratio of data for training (70% to 30% test split)
train_ratio = 0.7;
% Iterate over each activity class
activity_classes = unique(feature_table.labels);
for i = 1:length(activity_classes)
activity = activity_classes{i};
% Filter data for the current activity
indices = strcmp(feature_table.labels, activity);
activity_data = feature_table(indices, :);
% Shuffle the data to ensure randomness
shuffled_data = activity_data(randperm(size(activity_data, 1)), :);
% Split the data into training and testing sets
num_samples = size(shuffled_data, 1);
num_train_samples = round(train_ratio * num_samples);
num_test_samples = num_samples - num_train_samples;
train_data = shuffled_data(1:num_train_samples, :);
test_data = shuffled_data(num_train_samples+1:end, :);
% Save training and testing data for the current activity
train_file_name = fullfile(train_folder, [activity '_train.mat']);
test_file_name = fullfile(test_folder, [activity '_test.mat']);
save(train_file_name, 'train_data');
save(test_file_name, 'test_data');
end