function [discreteDataset] = discretize(dataset,N,type)
% the details of this discretizer are as follows
% N bin,
% type specifies either equal Freq (equal number of items in each bin) or
% equal width

if strcmp(type,'freq') == 1     % if equal frequency
    binSize = ceil(size(dataset,1)/N); % number of instances in each bin
    
    % make a same size matrix for discrete values
    discreteDataset = zeros(size(dataset,1),size(dataset,2));
    
    % process each column of the dataset one at a time
    % except the last column, which is the effort value
    binCounter = 0;
    binIndex = 0;
    for i = 1:(size(dataset,2)-1)
        [C IND] = sort(dataset(:,i));   % get the indices of sorted instances in column
        for j = 1:size(dataset,1)
            if mod(binIndex,binSize) == 0
                binCounter = binCounter + 1;
                binIndex = 0;
            end
            discreteDataset(IND(j),i) = binCounter;
            binIndex = binIndex + 1;
            
        end
    end
else % else if it is equal width
    epsilo = 0.00001;
    maxValues = max(dataset(:,1:(size(dataset,2)-1))) + epsilo; % min values of each column
    minValues = min(dataset(:,1:(size(dataset,2)-1))) -  epsilo; % max values of each column
    widthSizes = ((maxValues - minValues)./N); % width of each bin
    
    % make a same size matrix for discrete values
    discreteDataset = zeros(size(dataset,1),size(dataset,2));
    
    % process each column of the dataset one at a time
    % except the last column, which is the effort value
    for i = 1:(size(dataset,2)-1)
        discreteDataset(:,i) = ceil((dataset(:,i) - minValues(i))./widthSizes(i));
    end
end

% now copy the actual effort values, since they will not be discretized
discreteDataset(:,size(discreteDataset,2)) = dataset(:,size(dataset,2));

end