當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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.。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。