[R] knncat broken on R 2.14?

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Feb 2 11:59:40 CET 2012


Works for me.
Uwe Ligges

On 02.02.2012 02:09, Nick Matzke wrote:
> Hi,
>
> Until recently I was using the knncat classifier function of knncat on
> an old computer (2.12, Mac OS X 10.4), and everything worked great.
>
> However, now that I have updated to R 2.14.1 (on Mac OS X 10.7), knncat
> seems broken. Problems:
>
>
> 1. It seems to output verbose output by default, and regardless of
> whether I put 0 or 1 into the verbose option.
>
>
> 2. It seems to just predict everything to be class "0".
>
>
> 3. I can see this problem even when running the example script under
> ?knncat.
>
>
>
> Given example from ?knncat, and expected behavior:
> =======================
> library(knncat)
>
> library(MASS) # Load data set
> syncat <- knncat (synth.tr, classcol=3)
>
> ## Not run: syncat
> Train set misclass rate: 12.8
> synpred <- predict (syncat, synth.tr, synth.te, train.classcol=3,
> newdata.classcol=3)
> table (synpred, synth.te$yc)
>
> synpred 0 1
> 0 460 91
> 1 40 409
> =======================
>
>
>
> Actual behavior:
> ==========================================
>  > library(MASS) # Load data set
>  > syncat <- knncat (synth.tr, classcol=3)
>
> Global U:
>
> [,1] [,2] [,3] [,4] [,5]
> [1,] 3.20705e+02 1.91438e+02 1.51645e+02 1.20514e+02 8.21981e+01
> [2,] 1.91438e+02 1.14799e+02 9.09814e+01 7.22355e+01 4.92108e+01
> [3,] 1.51645e+02 9.09814e+01 7.21094e+01 5.72461e+01 3.89942e+01
> [4,] 1.20514e+02 7.22355e+01 5.72461e+01 4.54553e+01 3.09702e+01
> [5,] 8.21981e+01 4.92108e+01 3.89942e+01 3.09702e+01 2.11076e+01
> [6,] 5.57264e+01 3.34476e+01 2.65108e+01 2.10446e+01 1.43334e+01
> [7,] 2.51586e+01 1.52490e+01 1.20991e+01 9.58523e+00 6.51199e+00
> [8,] 1.45272e+01 8.85590e+00 7.03089e+00 5.56357e+00 3.77419e+00
> [9,] 8.30201e+00 5.07964e+00 4.03440e+00 3.19007e+00 2.16202e+00
> [10,] 3.36454e+00 2.07002e+00 1.64502e+00 1.29931e+00 8.79344e-01
>
> [,6] [,7] [,8] [,9] [,10]
> [1,] 5.57264e+01 2.51586e+01 1.45272e+01 8.30201e+00 3.36454e+00
> [2,] 3.34476e+01 1.52490e+01 8.85590e+00 5.07964e+00 2.07002e+00
> [3,] 2.65108e+01 1.20991e+01 7.03089e+00 4.03440e+00 1.64502e+00
> [4,] 2.10446e+01 9.58523e+00 5.56357e+00 3.19007e+00 1.29931e+00
> [5,] 1.43334e+01 6.51199e+00 3.77419e+00 2.16202e+00 8.79344e-01
> [6,] 9.74699e+00 4.45226e+00 2.58857e+00 1.48583e+00 6.06140e-01
> [7,] 4.45226e+00 2.07551e+00 1.22083e+00 7.05915e-01 2.91111e-01
> [8,] 2.58857e+00 1.22083e+00 7.22786e-01 4.19620e-01 1.74066e-01
> [9,] 1.48583e+00 7.05915e-01 4.19620e-01 2.44220e-01 1.01671e-01
> [10,] 6.06140e-01 2.91111e-01 1.74066e-01 1.01671e-01 4.25445e-02
>
> Global W:
>
> [,1] [,2] [,3] [,4] [,5]
> [1,] 3.68224e+02 2.36787e+02 1.93972e+02 1.58837e+02 1.12597e+02
> [2,] 2.36787e+02 1.58549e+02 1.32054e+02 1.09539e+02 7.88945e+01
> [3,] 1.93972e+02 1.32054e+02 1.11021e+02 9.27903e+01 6.74442e+01
> [4,] 1.58837e+02 1.09539e+02 9.27903e+01 7.82101e+01 5.74745e+01
> [5,] 1.12597e+02 7.88945e+01 6.74442e+01 5.74745e+01 4.31835e+01
>
> [...etc...lots of undesired detailed/verbose output, then...]
>
>  > syncat
> Training set misclass rate: 50%
>
>  > synpred <- predict (syncat, synth.tr, synth.te, train.classcol=3,
> + newdata.classcol=3)
>
>  > table (synpred, synth.te$yc)
>
> synpred 0 1
> 0 500 500
> ==========================================
>
>
>
>
> Any help would be much appreciated!
>
> Cheers,
> Nick
>
>
> PS computer details
> =====================
> knncat is version 1.1.11
> =====================
>
>
> ==========================================
> R version 2.14.1 (2011-12-22)
> Copyright (C) 2011 The R Foundation for Statistical Computing
> ISBN 3-900051-07-0
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type 'license()' or 'licence()' for distribution details.
>
> Natural language support but running in an English locale
>
> R is a collaborative project with many contributors.
> Type 'contributors()' for more information and
> 'citation()' on how to cite R or R packages in publications.
>
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 'help.start()' for an HTML browser interface to help.
> Type 'q()' to quit R.
>
> [R.app GUI 1.43 (5989) x86_64-apple-darwin9.8.0]
>
> ==========================================
>
>
>



More information about the R-help mailing list