Would changing the dimension space in knn classifier make space for more memory?
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Classification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!