kknn: Interfaces for kknn package for data science pipelines.

Description Usage Arguments Details Value Author(s) Examples

Description

Interfaces to kknn functions that can be used in a pipeline implemented by magrittr.

Usage

1
2
3

Arguments

data

data frame, tibble, list, ...

...

Other arguments passed to the corresponding interfaced function.

Details

Interfaces call their corresponding interfaced function.

Value

Object returned by interfaced function.

Author(s)

Roberto Bertolusso

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
## Not run: 
library(intubate)
library(magrittr)
library(kknn)


## ntbt_train.kknn: Training kknn
## ntbt_cv.kknn:
data(miete)

## Original function to interface
train.kknn(nmqm ~ wfl + bjkat + zh, data = miete,
           kmax = 25, kernel = c("rectangular", "triangular", "epanechnikov",
                                 "gaussian", "rank", "optimal"))
cv.kknn(nmqm ~ wfl + bjkat + zh, data = miete)

## The interface puts data as first parameter
ntbt_train.kknn(miete, nmqm ~ wfl + bjkat + zh,
                kmax = 25, kernel = c("rectangular", "triangular", "epanechnikov",
                                      "gaussian", "rank", "optimal"))
ntbt_cv.kknn(miete, nmqm ~ wfl + bjkat + zh)

## so it can be used easily in a pipeline.
miete %>%
  ntbt_train.kknn(nmqm ~ wfl + bjkat + zh,
                  kmax = 25, kernel = c("rectangular", "triangular", "epanechnikov",
                                        "gaussian", "rank", "optimal"))
miete %>%
  ntbt_cv.kknn(nmqm ~ wfl + bjkat + zh)

## ntbt_kknn: Weighted k-Nearest Neighbor Classifier
m <- dim(iris)[1]
val <- sample(1:m, size = round(m/3), replace = FALSE, prob = rep(1/m, m)) 
iris.learn <- iris[-val,]
iris.valid <- iris[val,]

## Original function to interface
kknn(Species ~ ., iris.learn, iris.valid, distance = 1, kernel = "triangular")

## The interface puts data as first parameter
ntbt_kknn(iris.learn, Species ~ ., iris.valid, distance = 1, kernel = "triangular")

## so it can be used easily in a pipeline.
iris.learn %>%
  ntbt_kknn(Species ~ ., iris.valid, distance = 1, kernel = "triangular")
## NOTE: there is (in your face) cheating! We should be able to supply
##       both iris.learn and iris.valid. It should be possible with intuBags.

## End(Not run)

rbertolusso/intubate documentation built on May 27, 2019, 3 a.m.