Would changing the dimension space in knn classifier make space for more memory?

1 view (last 30 days)
Would changing the dimension space in knn classifier make space for more memory? The LDA I was using could not contain more than 6400x21. My data set is 170884x21. Any advice?
Code:
function D = distfun(Train, Test, dist)
%DISTFUN Calculate distances from training points to test points.
[n,p] = size(Train);
D = zeros(n,size(Test,1));
numTest = size(Test,1);
switch dist
case 'sqeuclidean'
for i = 1:numTest
D(:,i) = sum((Train - Test(repmat(i,n,1),:)).^2, 2);
end
case 'cityblock'
for i = 1:numTest
D(:,i) = sum(abs(Train - Test(repmat(i,n,1),:)), 2);
end
case {'cosine','correlation'}
% Normalized both the training and test data.
normTrain = sqrt(sum(Train.^2, 2));
normTest = sqrt(sum(Test.^2, 2));
normData = sqrt(sum([Train;Test].^2, 2));
Train = Train ./ normTrain(:,ones(1,size(Train,2)));
if any(normData < eps) % small relative to unit-length data points
error('stats:knn:ZeroTestentroid', ...
'Zero cluster centroid created at iteration %d.',iter);
end
% This can be done without a loop, but the loop saves memory
allocations
for i = 1:numTest
D(:,i) = 1 - (Train * Test(i,:)') ./ normTest(i);
end
I tried changing the line, D = zeros(n,size(Test,1)); to D = zeros(n,size(Test,21)); will it help?

Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!