[R] outputs of KNN prediction

Tom Blackwell tblackw at umich.edu
Mon Feb 23 14:01:45 CET 2004


Qin  -

If you do  str(pred),  I think you will find that pred is
now a factor with 276 levels.  to convert it back into an
ordinary numeric vector, do

values <- as.numeric(as.character(pred))

-  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Mon, 23 Feb 2004, Qin Liu wrote:

> Hello there:
>
> I got 13 variables in my training/target set, the first 12 variables are
> mixture of numerical and categorical variables. The last one is the one I
> need
> to predict, and it is a numerical variable.
>
> >train<-read.table("train.txt")
> >test<-read.table("test.txt")
> >cl<-factor(train[,13])
> >pred<-knn(train, test, clk=3, prob=TRUE)
> >pred
> I got output on the screen as following
>
>  8.10832229  8.831127635 7.592870288 8.521782644 6.376726948 6.914730893
>  9.71534911  8.658171785 6.104793232 7.247080585 6.298949247 5.105945474
>  7.508238775 7.65396918  8.831127635 7.912056888 6.381816017 7.211556733
>
>  276 levels ............
>
> Then I tried to calculate a formula:(actual-pred)/actual, which includes
> pred
> values. However, I cannot do this even I convert the factors in pred to
> vectors. Can anybody help??
>
> Thank you very much indeed,
>
> Qin
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list