Last data update: 2014.03.03

R: knn classification
knnClassificationR Documentation

knn classification

Description

Classification using for the k-nearest neighbours algorithm.

Usage

knnClassification(object, assessRes, scores = c("prediction", "all", "none"),
  k, fcol = "markers", ...)

Arguments

object

An instance of class "MSnSet".

assessRes

An instance of class "GenRegRes", as generated by knnOptimisation.

scores

One of "prediction", "all" or "none" to report the score for the predicted class only, for all cluster or none.

k

If assessRes is missing, a k must be provided.

fcol

The feature meta-data containing marker definitions. Default is markers.

...

Additional parameters passed to knn from package class.

Value

An instance of class "MSnSet" with knn and knn.scores feature variables storing the classification results and scores respectively.

Author(s)

Laurent Gatto

Examples

library(pRolocdata)
data(dunkley2006)
## reducing parameter search space and iterations 
params <- knnOptimisation(dunkley2006, k = c(3, 10), times = 3)
params
plot(params)
f1Count(params)
levelPlot(params)
getParams(params)
res <- knnClassification(dunkley2006, params)
getPredictions(res, fcol = "knn")
getPredictions(res, fcol = "knn", t = 0.75)
plot2D(res, fcol = "knn")

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (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.

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.

> library(pRoloc)
Loading required package: MSnbase
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Loading required package: mzR
Loading required package: Rcpp
Loading required package: BiocParallel
Loading required package: ProtGenerics

This is MSnbase version 1.20.7 
  Read '?MSnbase' and references therein for information
  about the package and how to get started.


Attaching package: 'MSnbase'

The following object is masked from 'package:stats':

    smooth

The following object is masked from 'package:base':

    trimws

Loading required package: MLInterfaces
Loading required package: annotate
Loading required package: AnnotationDbi
Loading required package: stats4
Loading required package: IRanges
Loading required package: S4Vectors

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

Loading required package: XML
Loading required package: cluster

This is pRoloc version 1.12.4 
  Read '?pRoloc' and references therein for information
  about the package and how to get started.

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/pRoloc/knnClassification.Rd_%03d_medium.png", width=480, height=480)
> ### Name: knnClassification
> ### Title: knn classification
> ### Aliases: knnClassification knnPrediction
> 
> ### ** Examples
> 
> library(pRolocdata)

This is pRolocdata version 1.10.0.
Use 'pRolocdata()' to list available data sets.
> data(dunkley2006)
> ## reducing parameter search space and iterations 
> params <- knnOptimisation(dunkley2006, k = c(3, 10), times = 3)
   |                                                                               |                                                                      |   0%   |                                                                               |=====                                                                 |   7%   |                                                                               |=========                                                             |  13%   |                                                                               |==============                                                        |  20%   |                                                                               |===================                                                   |  27%   |                                                                               |=======================                                               |  33%   |                                                                               |============================                                          |  40%   |                                                                               |=================================                                     |  47%   |                                                                               |=====================================                                 |  53%   |                                                                               |==========================================                            |  60%   |                                                                               |===============================================                       |  67%   |                                                                               |===================================================                   |  73%   |                                                                               |========================================================              |  80%   |                                                                               |=============================================================         |  87%   |                                                                               |=================================================================     |  93%   |                                                                               |======================================================================| 100%
> params
Object of class "GenRegRes"
Algorithm: knn 
Hyper-parameters:
 k: 3 10
Design:
 Replication: 3 x 5-fold X-validation
 Partitioning: 0.2/0.8 (test/train)
Results
 macro F1:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 0.9788  0.9894  1.0000  0.9929  1.0000  1.0000 
 best k: 3   
> plot(params)
> f1Count(params)

3 
2 
> levelPlot(params)
> getParams(params)
k 
3 
> res <- knnClassification(dunkley2006, params)
> getPredictions(res, fcol = "knn")
ans
     ER lumen   ER membrane         Golgi Mitochondrion            PM 
           20           180            94           106           138 
      Plastid      Ribosome           TGN       vacuole 
           49            51            21            30 
MSnSet (storageMode: lockedEnvironment)
assayData: 689 features, 16 samples 
  element names: exprs 
protocolData: none
phenoData
  sampleNames: M1F1A M1F4A ... M2F11B (16 total)
  varLabels: membrane.prep fraction replicate
  varMetadata: labelDescription
featureData
  featureNames: AT1G09210 AT1G21750 ... AT4G39080 (689 total)
  fvarLabels: assigned evidence ... knn.pred (11 total)
  fvarMetadata: labelDescription
experimentData: use 'experimentData(object)'
  pubMedIds: 16618929 
Annotation:  
- - - Processing information - - -
Loaded on Thu Jul 16 22:53:08 2015. 
Normalised to sum of intensities. 
Added markers from  'mrk' marker vector. Thu Jul 16 22:53:08 2015 
Performed knn prediction (k=3) Thu Jul  7 01:43:37 2016 
Added knn predictions according to global threshold = 0 Thu Jul  7 01:43:37 2016 
 MSnbase version: 1.17.12 
> getPredictions(res, fcol = "knn", t = 0.75)
ans
     ER lumen   ER membrane         Golgi Mitochondrion            PM 
           15           173            83           103           120 
      Plastid      Ribosome           TGN       unknown       vacuole 
           49            44            16            56            30 
MSnSet (storageMode: lockedEnvironment)
assayData: 689 features, 16 samples 
  element names: exprs 
protocolData: none
phenoData
  sampleNames: M1F1A M1F4A ... M2F11B (16 total)
  varLabels: membrane.prep fraction replicate
  varMetadata: labelDescription
featureData
  featureNames: AT1G09210 AT1G21750 ... AT4G39080 (689 total)
  fvarLabels: assigned evidence ... knn.pred (11 total)
  fvarMetadata: labelDescription
experimentData: use 'experimentData(object)'
  pubMedIds: 16618929 
Annotation:  
- - - Processing information - - -
Loaded on Thu Jul 16 22:53:08 2015. 
Normalised to sum of intensities. 
Added markers from  'mrk' marker vector. Thu Jul 16 22:53:08 2015 
Performed knn prediction (k=3) Thu Jul  7 01:43:37 2016 
Added knn predictions according to global threshold = 0.75 Thu Jul  7 01:43:37 2016 
 MSnbase version: 1.17.12 
> plot2D(res, fcol = "knn")
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>