% dataset_generate.m
% Generation of a small dataset with two classes with Gaussian distribution
% function [data, label] = dataset_generate(N)
% Input: N is the number of samples per class
% Outputs: data array, class label vector
% Export the dataset to a text file ('mvnrnd.txt') to be imported by sklearn
% Explain the K Nearest Neighbor (KNN) algorithm
% Dr. David Pan, UAH

function [data, label] = dataset_generate(N)

close all
% Generate data entries for Class 1
m1 = [-4, 0];   % Mean vector
c1 = [1,0; 0,1]; % Covariance matrix
rng default  % For reproducibility
r1 = mvnrnd(m1,c1,N);

data_C1 = zeros(N, 2);
data_C1 = r1;
label_C1 = ones(N, 1);

% Generate data entries for Class 2
m2 = [4, 0];
c2 = [9,4; 4,9];
rng default  % For reproducibility
r2 = mvnrnd(m2,c2,N);

data_C2 = zeros(N, 2);
data_C2 = r2;
label_C2 = 2*ones(N, 1);

% Combine data of two classes
data = vertcat (data_C1, data_C2);
label = vertcat (label_C1, label_C2);

% Export the dataset to a CSV file
data_label = horzcat(data, label);
writematrix(data_label, 'mvnrnd.csv');

