%% function [X, y] = preprocess(X, y)
% Applies preprocessing to data values X, and target y
% Removes all X rows, and y rows where y values are missing
% Replaces all missing X values with mean values of the column/feature
% Outliers are replaced with median value 
% Values are changed to Z-scores (standard scaler)

function [X, y] = preprocess(X, y)
    mu = mean(X, 1, 'omitmissing');
    
    % find the indices of missing feature values cells
    indx = ismissing(X(:,:));

    % replace with corresponding column (feature) mean
    [r, c] = find(indx);    % get row "r", and column "c" 

    for i = 1:length(r)
        X(r(i), c(i)) = mu(c(i));
    end

    % replace outliers with median
    X = filloutliers(X, "center");

    % standard scaler
    X = normalize(X, 1, 'range');
end