In library(package, lib.loc = lib.loc,character.only = TRUE, there is no package called ‘kknn’

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了In library(package, lib.loc = lib.loc,character.only = TRUE, there is no package called ‘kknn’相关的知识,希望对你有一定的参考价值。

In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  : there is no package called ‘kknn’

目录

In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  : there is no package called ‘kknn’

问题:

解决:

完整错误:


问题:

library(mlr)

library(tidyverse)

此处使用的数据集包含在mlr包中的fuelsubset.task中;

使用as_tibble函数将数据框dataframe转化为tibble;

使用mlr的getTaskData函数从任务中提取数据;

数据包含119个样本、367个特征;

heatan变量是目标变量;

data("fuelsubset.task")

fuel <- getTaskData(fuelsubset.task)

fuelTib <- as_tibble(fuel)

fuelTib

# A tibble: 129 x 367
   heatan   h20 UVVIS.UVVIS.1 UVVIS.UVVIS.2 UVVIS.UVVIS.3 UVVIS.UVVIS.4
    <dbl> <dbl>         <dbl>         <dbl>         <dbl>         <dbl>
 1   26.8  2.3         0.874          0.748        0.774         0.747
 2   27.5  3          -0.855         -1.29        -0.833        -0.976
 3   23.8  2.00       -0.0847        -0.294       -0.202        -0.262
 4   18.2  1.85       -0.582         -0.485       -0.328        -0.539
 5   17.5  2.39       -0.644         -1.12        -0.665        -0.791
 6   20.2  2.43       -0.504         -0.890       -0.662        -0.744
 7   15.1  1.92       -0.569         -0.507       -0.454        -0.576
 8   20.4  3.61        0.158          0.186        0.0303        0.183
 9   26.7  2.5         0.334          0.191        0.0777        0.0410
10   24.9  1.28        0.0766         0.266        0.0808       -0.0733
# ... with 119 more rows, and 361 more variables

数据预处理(为方便数据可视化)

fuelUntidy <- fuelTib %>%
  mutate(id = 1:nrow(.)) %>%
  gather(key = "variable", value = "absorbance",
  c(-heatan, -h20, -id)) %>%
  mutate(spectrum = str_sub(variable, 1, 3),
         wavelength = as.numeric(str_extract(variable, "(\\\\d)+")))

fuelUntidy



# A tibble: 47,085 x 7
   heatan   h20    id variable      absorbance spectrum wavelength
    <dbl> <dbl> <int> <chr>              <dbl> <chr>         <dbl>
 1   26.8  2.3      1 UVVIS.UVVIS.1     0.874  UVV               1
 2   27.5  3        2 UVVIS.UVVIS.1    -0.855  UVV               1
 3   23.8  2.00     3 UVVIS.UVVIS.1    -0.0847 UVV               1
 4   18.2  1.85     4 UVVIS.UVVIS.1    -0.582  UVV               1
 5   17.5  2.39     5 UVVIS.UVVIS.1    -0.644  UVV               1
 6   20.2  2.43     6 UVVIS.UVVIS.1    -0.504  UVV               1
 7   15.1  1.92     7 UVVIS.UVVIS.1    -0.569  UVV               1
 8   20.4  3.61     8 UVVIS.UVVIS.1     0.158  UVV               1
 9   26.7  2.5      9 UVVIS.UVVIS.1     0.334  UVV               1
10   24.9  1.28    10 UVVIS.UVVIS.1     0.0766 UVV               1
# ... with 47,075 more rows

数据可视化(关系图、分面关系图)

uelUntidy %>%
  ggplot(aes(absorbance, heatan, col = as.factor(wavelength))) +
  facet_wrap(~ spectrum, scales = "free_x") +
  geom_smooth(se = FALSE, size = 0.2) +
  ggtitle("Absorbance vs heatan for each wavelength") +
  theme_bw() +
  theme(legend.position = "none")

fuelUntidy %>%
  ggplot(aes(wavelength, absorbance, group = id, col = heatan)) +
  facet_wrap(~ spectrum, scales = "free_x") +
  geom_smooth(se = FALSE, size = 0.2) +
  ggtitle("Wavelength vs absorbance for each batch") +
  theme_bw()

fuelUntidy %>%
  ggplot(aes(h20, heatan)) +
  geom_smooth(se = FALSE) +
  ggtitle("Humidity vs heatan") +
  theme_bw()

R语言使用mlr包的makeRegrTask函数创建回归任务、makeLearner函数指定回归学习函数为KNN回归模型

fuelTask <- makeRegrTask(data = fuelTib, target = "heatan")

kknn <- makeLearner("regr.kknn")



> kknn <- makeLearner("regr.kknn")
Loading required package: kknn
Error in requirePackages(package, why = stri_paste("learner", id, sep = " "),  : 
  For learner regr.kknn please install the following packages: kknn
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘kknn’

> install.packages("kknn")
trying URL 'https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/contrib/4.0/kknn_1.3.1.zip'
Content type 'application/zip' length 335586 bytes (327 KB)
downloaded 327 KB

解决:

是因为没有安装kknn包,安装了就好了。

> install.packages("kknn")
trying URL 'https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/contrib/4.0/kknn_1.3.1.zip'
Content type 'application/zip' length 335586 bytes (327 KB)
downloaded 327 KB

fuelTask <- makeRegrTask(data = fuelTib, target = "heatan")

kknn <- makeLearner("regr.kknn")



> kknn
Learner regr.kknn from package kknn
Type: regr
Name: K-Nearest-Neighbor regression; Short name: kknn
Class: regr.kknn
Properties: numerics,factors
Predict-Type: response
Hyperparameters: 

完整错误:

> kknn <- makeLearner("regr.kknn")
Loading required package: kknn
Error in requirePackages(package, why = stri_paste("learner", id, sep = " "),  : 
  For learner regr.kknn please install the following packages: kknn
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘kknn’

参考:https://www.rdocumentation.org/packages/kknn/versions/1.3.1
参考:https://github.com/mlr-org/mlr/issues/1689

以上是关于In library(package, lib.loc = lib.loc,character.only = TRUE, there is no package called ‘kknn’的主要内容,如果未能解决你的问题,请参考以下文章

Error in library(e1071) : there is no package called 'e1071'

Python入门之面向对象module,library,package之间区别

序列处理之seqinr(fetch)

scala-library-2.10.3.jar 与 sbt-native-packager 0.7+ 的重复映射

#yyds干货盘点#dart系列之:创建Library package

安装EFCodeFirst 出错 调试Library Package Manager → Package Manager Console 出现的框 是不可写入 不