当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R butcher axe-kknn 砍掉 kknn。


kknn 对象是从创建的克尼恩包,用于执行加权 k-Nearest 邻居进行分类、回归和聚类。

用法

# S3 method for kknn
axe_call(x, verbose = FALSE, ...)

# S3 method for kknn
axe_env(x, verbose = FALSE, ...)

# S3 method for kknn
axe_fitted(x, verbose = FALSE, ...)

参数

x

一个模型对象。

verbose

每次执行 ax 方法时打印信息。记录释放了多少内存以及禁用了哪些函数。默认为 FALSE

...

与砍伐相关的任何其他参数。

砍掉 kknn 对象。

例子

# Load libraries
library(parsnip)
library(rsample)
library(rpart)
library(kknn)
#> 
#> Attaching package: ‘kknn’
#> The following object is masked from ‘package:caret’:
#> 
#>     contr.dummy

# Load data
set.seed(1234)
split <- initial_split(kyphosis, prop = 9/10)
spine_train <- training(split)

# Create model and fit
kknn_fit <- nearest_neighbor(mode = "classification",
                             neighbors = 3,
                             weight_func = "gaussian",
                             dist_power = 2) %>%
  set_engine("kknn") %>%
  fit(Kyphosis ~ ., data = spine_train)

out <- butcher(kknn_fit, verbose = TRUE)
#> ✔ Memory released: 7.78 kB

# \donttest{
# Another kknn model object
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,]
kknn_fit <- kknn(Species ~ .,
                 iris.learn,
                 iris.valid,
                 distance = 1,
                 kernel = "triangular")
out <- butcher(kknn_fit, verbose = TRUE)
#> ✔ Memory released: 47.10 kB
#> ✖ Disabled: `print()`, `summary()`, and `fitted()`
# }
源代码:R/kknn.R

相关用法


注:本文由纯净天空筛选整理自Davis Vaughan等大神的英文原创作品 Axing an kknn.。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。