Comments (6)
Hi @KlausVigo , any thoughts on this?
from kknn.
Hi @kenahoo ,
you are right, this looks like an underflow or overflow problem. What system are you using, maybe you can send me the output of sessionInfo() ?
On my machine your code is working, so I can't really reproduce your problem.
...
kmax = 3L, kernel = "rectangular")
Type of response variable: continuous
minimal mean absolute error: 0.10675
Minimal mean squared error: 0.02878625
Best kernel: rectangular
Best k: 1
Regards,
Klaus
from kknn.
Hi Klaus,
Actually, it seems to be non-deterministic. Here are a few runs in a row:
> do.call(train.kknn, args)
Error in cl[C] : only 0's may be mixed with negative subscripts
> do.call(train.kknn, args)
Error in best[1, 2] : subscript out of bounds
> do.call(train.kknn, args)
Error in best[1, 2] : subscript out of bounds
> do.call(train.kknn, args)
Error in cl[C] : only 0's may be mixed with negative subscripts
> do.call(train.kknn, args)
Error in best[1, 2] : subscript out of bounds
> do.call(train.kknn, args)
Call:
(function (formula, data, kmax = 11, ks = NULL, distance = 2, kernel = "optimal", ykernel = NULL, scale = TRUE, contrasts = c(unordered = "contr.dummy", ordered = "contr.ordinal"), ...) { if (is.null(ykernel)) ykernel = 0 weight.y = function(l = 1, diff = 0) { k = diff + 1 result = matrix(0, l, l)
# ... (that one was successful)
My session info:
> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin17.7.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.5/lib/libopenblasp-r0.3.5.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] kknn_1.3.1
loaded via a namespace (and not attached):
[1] compiler_3.5.2 magrittr_1.5 Matrix_1.2-15 igraph_1.2.2
[5] grid_3.5.2 pkgconfig_2.0.2 lattice_0.20-38
from kknn.
I took R (mostly) out of the chain, and it looks like it's non-deterministic at the C level. Stepping through with the lldb
debugger, I see this:
(lldb) p dmEuclid(mm_data, mm_data, &m, &p, &q, dm, cl, &k, we)
(lldb) p cl
(int [20]) $2 = {
[0] = 0
[1] = 1
[2] = 2
[3] = 3
[4] = 2
[5] = 0
[6] = 0
[7] = 2
[8] = 3
[9] = 2
[10] = 3
[11] = 0
[12] = 1
[13] = 3
[14] = 1
[15] = 1
[16] = 0
[17] = 1
[18] = 3
[19] = 1
}
(lldb) p dmEuclid(mm_data, mm_data, &m, &p, &q, dm, cl, &k, we)
(lldb) p cl
(int [20]) $3 = {
[0] = 0
[1] = 1
[2] = 2
[3] = 3
[4] = 2
[5] = 0
[6] = 0
[7] = 2
[8] = 3
[9] = 2
[10] = 3
[11] = 0
[12] = 1
[13] = 3
[14] = 1
[15] = 1
[16] = -1610612736
[17] = 1
[18] = 3
[19] = 1
}
I also noticed some mismatches between the order of argument names that train.kknn
is passing, and what dmEuclid
accepts:
.C("dmEuclid",
as.double(mm.data),
as.double(mm.data),
as.integer(m), <---- different order
as.integer(p), <---- different order
as.integer(q), <---- different order
dm = double((kmax + 2L) * p),
cl = integer((kmax + 2L) * p),
k = as.integer(kmax + 2),
as.double(we),
PACKAGE = "kknn")
void dmEuclid(double *learn,
double *valid,
int *n, <---- different order
int *m, <---- different order
int *p, <---- different order
double *dm,
int *cl,
int *k,
double *weights)
Any chance this is the issue?
from kknn.
Hi @kenahoo,
I should rename the parameters to correspond in the R and C code.
I think I finally figured it out. I kind of assumed that kmax + 2
is smaller the number of observations.
It should be now to work if kmax + 1
is equal to the number of observations and decreases kmax otherwise.
Can you check if my last commit fixes your problem?
from kknn.
Hi @KlausVigo , I think that fixes the problem indeed.
Curiously, I could only get this problem to manifest when running R interactively, not through Rscript. Maybe memory initialization is different in that case or something.
Thanks.
from kknn.
Related Issues (20)
- add type parameter in predict.kknn HOT 1
- [Bug] `kknn` returns a vector instead of a matrix for D and C when k = 1 HOT 1
- contr.ordinal
- cv.kknn error when response is a factor
- cv.kknn fold sizes are different HOT 3
- running when imported HOT 1
- error in predicting with predict.train.kknn
- Outdated examples and dangerous design choices HOT 1
- Citation link does not work anymore. HOT 1
- ks too large
- predict.train.kknn() does not respect all parameters from train.kknn() HOT 1
- Error When Character Level In Train But Not Test
- New CRAN release?
- Confidence/prediction intervals for predictions
- specClust error HOT 3
- na.action ? HOT 1
- ARPACK error in specClust
- Memory management HOT 4
- [Bug] `kknn` computes incorrect neighbours for k >= train_size - 1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kknn.