I have a dataset with 200K samples (cases) and 30 variables. Every distance-based method for clustering or dimension reduction technique that I use, such as *DBSCAN*, *Hierarchical Clustering*, *LLE*, *Isomap* and … fail to run on my machine (normally I get `R Session Terminated`

error) due to the large distance file being generated. (*Distance calculation requires o(n^2) time and space*)

Is there any solution to handle this problem? Is there any good package for the mentioned clustering or dimensionality reduction in R or Matlab that is suitable ?

Cross Validated Asked by Matin Kh on December 27, 2020

1 AnswersMaybe you could try Mini-Batch K-Means. I have Matlab code for it:

```
function [c,counts,idx] = mbkmeans(x,k,c,counts)
[N,D] = size(x);
if ~exist('c','var') || isempty(c)
c = x(1:min([k N]),:) + bsxfun(@times,randn(min([k N]),D)*0.001,std(x));
if N < k
c(N+1:k,:) = bsxfun(@plus,mean(x),bsxfun(@times,randn(k-N,D),std(x)));
end;
end;
if ~exist('counts','var') || isempty(counts)
counts = zeros(k,1);
end;
idx = knnsearch(c,x,'k',1);
add = full(sparse(idx,1,1));
counts(idx) = counts(idx) + add(idx);
lr = 1 ./ counts(idx);
for i = 1:N
c(idx(i),:) = (1 - lr(i)) * c(idx(i),:) + lr(i) * x(i,:);
end;
```

Usage:

```
clusters = mbkmeans(yourdata,numberofclusters);
```

You may feed it your entire dataset at once and you're done. Or you may feed it smaller subsets. In this case, use it like this:

```
[c1, counts1] = mbkmeans(subset1,numberofclusters);
[c2, counts2] = mbkmeans(subset2,numberofclusters, c1, counts1); %start clustering using previously created clusters
[c3, counts3] = mbkmeans(subset3,numberofclusters, c2, counts2);
...
[cn, countsn, indices] = mbkmeans(subsetn,numberofclusters, c(n-1), counts(n-1));
```

For R, there is the stream package (explanation here). You may also take a look at this, this and this.

Answered by rcpinto on December 27, 2020

0 Asked on December 1, 2021 by user989761

1 Asked on December 1, 2021 by josh-davis

0 Asked on December 1, 2021 by yy-shi

1 Asked on December 1, 2021

1 Asked on December 1, 2021 by diana-petitti

1 Asked on November 29, 2021

dependent variable logistic multiple regression predictive models sensitivity specificity

4 Asked on November 29, 2021 by zhi-zhao

1 Asked on November 29, 2021

non negative matrix factorization optimization overfitting regularization

1 Asked on November 29, 2021 by ama-perera

4 Asked on November 29, 2021 by lelouche-lamperouge

2 Asked on November 29, 2021 by user292024

1 Asked on November 29, 2021

1 Asked on November 29, 2021 by user292068

0 Asked on November 29, 2021

0 Asked on November 29, 2021 by user810739

confidence interval prediction prediction interval predictive models

1 Asked on November 29, 2021 by afternoon

hypothesis testing normal distribution probability sample sample size

1 Asked on November 29, 2021

1 Asked on November 29, 2021 by atakan

4 Asked on November 29, 2021 by richie-cotton

Get help from others!

Recent Questions

- Why fry rice before boiling?
- MouseLook Script “Pops” back to the last value when the script is enabled after being disabled or destroyed
- Unity app crashes when using unmodified custom Android manifest (didn’t find class “UnityPlayerActivity”)
- How do i draw a ray in unity
- How to test consistency of responses?

Recent Answers

- DMGregory on MouseLook Script “Pops” back to the last value when the script is enabled after being disabled or destroyed
- Joshua Engel on Why fry rice before boiling?
- Jon Church on Why fry rice before boiling?
- haakon.io on Why fry rice before boiling?
- Peter Machado on Why fry rice before boiling?

© 2022 AnswerBun.com. All rights reserved.