- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 kaggle 的 pokemon 数据通过 preProcess()
练习 KNN 插补,但是当我这样做时,我在 predict()
之后遇到了以下消息步。我想知道我是否使用了不正确的数据格式,或者某些列是否具有不适当的“类”。下面是我的代码。
library(dplyr)
library(ggplot2)
library(tidyr)
library(reshape2)
library(caret)
library(skimr)
library(psych)
library(e1071)
library(data.table)
pokemon <- read.csv("https://www.dropbox.com/s/znbta9u9tub2ox9/pokemon.csv?dl=1")
pokemon = tbl_df(pokemon)
# select relevant features
df <- select(pokemon, hp, weight_kg, height_m, sp_attack, sp_defense, capture_rate)
pre_process_missing_data <- preProcess(df, method="knnImpute")
classify_legendary <- predict(pre_process_missing_data, newdata = df)
Error: Must subset rows with a valid subscript vector.
x Subscript `nn$nn.idx` must be a simple vector, not a matrix.
Run `rlang::last_error()` to see where the error occurred.
最佳答案
preProcess
的输入必须是 data.frame
.这有效:
pre_process_missing_data <- preProcess(as.data.frame(df), method="knnImpute")
classify_legendary <- predict(pre_process_missing_data, newdata = df)
classify_legendary
> classify_legendary
# A tibble: 801 x 6
hp weight_kg height_m sp_attack sp_defense capture_rate
<dbl> <dbl> <dbl> <dbl> <dbl> <chr>
1 -0.902 -0.498 -0.429 -0.195 -0.212 45
2 -0.337 -0.442 -0.152 0.269 0.325 45
3 0.415 0.353 0.774 1.57 1.76 45
4 -1.13 -0.484 -0.522 -0.349 -0.748 45
5 -0.412 -0.388 -0.0591 0.269 -0.212 45
6 0.340 0.266 0.496 2.71 1.58 45
7 -0.939 -0.479 -0.615 -0.659 -0.247 45
8 -0.375 -0.356 -0.152 -0.195 0.325 45
9 0.378 0.221 0.404 1.97 1.58 45
10 -0.902 -0.535 -0.800 -1.59 -1.82 255
# ... with 791 more rows
关于r - 使用 knnImpute 时 preProcess() 中的 "Error: Must subset rows with a valid subscript vector",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62085827/
我理解缩放意味着以均值 (mean=0) 为中心并使单位方差 (variance=1)。 但是,scikit-learn 中的 preprocessing.scale(x) 和 preprocessi
我有一个以 float 作为数据的数据框,我想规范化数据,所以首先我将其转换为 int (否则我会出现错误 ValueError: 输入包含 NaN、无穷大或对于 dtype 来说太大的值('floa
我计划分发 SubSpec (适合 < 600 行的 xUnit 的小型 BDD 扩展)作为单个 .cs 文件而不是完整的 dll。 SubSpec 具有 Silverlight 和 .NET 风格,
我一直在探索用于变量转换的新 recipes 包,作为机器学习管道的一部分。由于所有新扩展,我选择了这种方法 - 从使用 caret 的 preProcess 函数升级。但我发现这些包对于转换后的数据
我有一个名为 size_array 的连续变量列表。我一直在像这样从 [0, 1] 缩放它们: max_abs_scaler = preprocessing.MinMaxScaler() scaled
我正在使用可视化 cl.exe 编译器在预处理后获取中间文件。所有的 #define 都被删除了。有没有可能将它们保留在中间文件中? 最佳答案 没有。预处理的任务之一是删除所有 #define 和其他
我想处理我的数据中的 NA 值,但不想缩放和居中,所以我只是这样做: preProcess(data, method = "knnImpute", k=10) 或这个: preProcess(data
如何获取tf.keras.preprocessing.image_dataset_from_directory中的文件个数? train_ds = tf.keras.preprocessing.ima
在 sklearn documentation说“规范”可以是其中之一 norm : ‘l1’, ‘l2’, or ‘max’, optional (‘l2’ by default) The norm
我想在触摸 UIButton 时添加动画效果。有没有办法在 Button 被发送到它的操作之前运行一个函数? 最佳答案 当您开始按下按钮时将调用以下操作。 @IBAction internal fun
我已经阅读了 scikit learn 网站上的手册,但我仍然不知道该命令背后的数学公式是什么。 >>> from sklearn import preprocessing >>> import nu
我想知道是否可以使用 gcc 输出“预处理”代码但“忽略”(不扩展)包括: ES 我得到了这个主要的: #include #define prn(s) printf("this is a macro
Python 3.5,来自 sklearn 的预处理 df = quandl.get('WIKI/GOOGL') X = np.array(df) X = preprocessing.scale(X)
为了正确调试 C++ 中的复杂宏,我通常在它们上运行预处理器,以便准确查看生成的代码的样子。 有类似“预处理”模板代码的方法吗? 最佳答案 一种方法(依赖于编译器)是在每个编译器步骤之后使用转储。我写
我正在尝试从 Sklearn 导入 StandardScalar,进行预处理,但它一直给我一个错误。 这是确切的错误: ImportError
如果客户端有办法 GWT 在客户端计算机上预处理文件的代码? 例如,在将文件提交到服务器之前计算它的校验和。 最佳答案 不,这是不可能的。文件的操作是由浏览器完成的,而不是 HTML 代码。 想想看,
我正在关注 this文档聚类教程。作为输入,我提供了一个可以下载的 txt 文件 here .它是 3 个其他 txt 文件的组合文件,使用\n 分隔。创建 tf-idf 矩阵后,我收到此警告: ,,
$ cabal install arithmoi-0.4.0.3 导致多个错误,例如: Math/NumberTheory/Moduli.hs:489:4: error: invalid p
#define A(a) "str" ## a ## test A(_) 根据 17.6.4.3.5在 C++11 标准中 Literal suffix identifiers that do no
我正在使用sklearn.neural_network.MLPClassifier构建神经网络: clf = sklearn.neural_network.MLPClassifier(hidd
我是一名优秀的程序员,十分优秀!