- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
sklearn提供了transform()
方法来应用one-hot编码器。
要使用transform()
方法,在调用transform()
方法之前需要fit_transform()
,否则
np.array([[1, 1], [2, 1], [3, 2], [np.nan, 2]])
from sklearn.impute import SimpleImputer
my_imputer = SimpleImputer()
my_imputer.transform(df)
出现错误
NotFittedError: This SimpleImputer instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.
在transform()
之前调用fit_transform()
my_imputer.fit_transform(df)
my_imputer.transform(df)
修复此错误。
问题是,为什么transform()
需要fit_transform()
?
最佳答案
在 fit()
期间,输入器了解数据的平均值、中位数等,然后在 transform()
期间将其应用于缺失值。
fit_transform()
只是组合这两种方法的简写。所以本质上是:
fit(X, y)
:- 了解所提供数据的所需方面,并返回具有学习参数的新对象。它不会以任何方式更改提供的数据。
transform()
:- 实际上将提供的数据转换为新形式。
fit_transform(df)
不需要在转换之前调用。只需要调用fit()
。一般来说,您描述的序列是通过数据的训练和测试分割来完成的。像这样的东西:
# Combining the learning of parameters from training data and transforming into a single step.
X_train_new = my_imputer.fit_transform(X_train)
# We dont want to learn about test data, only change it according to previously learnt information
X_test_new = my_imputer.transform(X_test)
上面的代码片段可以分解为:
# It learns about the data and does nothing else
my_imputer.fit(X_train)
# Calling transform to apply the learnt information on supplied data
X_train_new = my_imputer.transform(X_train)
X_test_new = my_imputer.transform(X_test)
关于python - sklearn.impute SimpleImputer : why does transform() need fit_transform() first?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56036248/
我的代码无法正常工作,因为我从机器学习 A-Z™:数据科学中的 Python 和 R 实践教程类(class)中逐字复制。我使用的是 Python 3.7,我已经在我的环境中安装了 scikit-le
我正在尝试在 google cloud ai 平台上创建一个版本,但找不到 impute 模块 No module named 'sklearn.impute._base; 'sklearn.impu
我正在对数据集进行预处理,我得到了该行的错误原因 imputer = imputer.fit(X [:,1:3])。我不明白哪个?我理解imputer = Imputer(missing_values
问题是我无法从 sklearn 导入模块。 from sklearn.impute import SimpleImputer ModuleNotFoundError: No module named
print(np.shape(ar_fulldata_input_xx)) Output: (9027, 1443) 现在,我使用 Imputer 来估算数据帧 ar_fulldata_input_x
我目前正在学习 sklearn imputer我发现有一种策略没有被 imputers 实现。 我想构建一个管道,删除具有任何缺失值的列或删除所有具有缺失值的行。 我为什么要这个? 因为我想进行网格搜
我正在尝试使用 Imputer 来查找缺失值。我还想跟踪具有所有缺失值的列,但因为否则我不知道其中哪些(列)已被处理:是否还可以返回包含所有缺失值的列? Impute Notes When axis=
我有一个包含缺失值 NaN 的特征矩阵,因此我需要先初始化这些缺失值。但是,最后一行提示并抛出以下错误行:预期序列或类数组,得到 Imputer(axis=0, copy=True, missing_
目前我正在尝试用 pandas 估算因变量。 (不要问为什么。)这是数据集 y.head(15) Out[138]: 0 13495.0 1 16500.0 2 16500.0
我有以下问题:我有一个 pandas 数据框,其中缺失值由字符串 na 标记。我想在其上运行一个 Imputer 以用列中的平均值替换缺失值。根据 sklearn 文档,参数 missing_valu
我试图在数据框中填充我的 NA 数据。我做了简单的数据: library(mice) first <- c(1,2,3,4,5,NA,7,8,9,NA) second<- c(1,2,NA,4,5,6
我不确定为什么,但在应用 knn.impute 时出现以下错误: Error in storage.mode(use.data) <- "double" : (list) object canno
考虑 data其中包含以下一些 nan: Column-1 Column-2 Column-3 Column-4 Column-5 0 NaN 15.0 63.0
有没有办法让 Scikit-learn Imputer 查找并替换多个被视为“缺失值”的值? 例如,我想做类似的事情 imp = Imputer(missing_values=(7,8,9)) 但根据
我正在练习机器学习中的数据集,在获取缺失值时,我使用了 imputer 类,但它给了我一个错误:数组索引太多。对于这个错误,我只是查看了所有 numpy 模块,但我没有任何想法来解决它。 import
有没有办法使用 sklearn.preprocessing 对象来估算分类值?我想最终创建一个预处理对象,我可以将其应用于新数据并以与旧数据相同的方式对其进行转换。 我正在寻找一种方法来做到这一点,以
docs对于 scikit-learn 的 Imputation transformer 说 When axis=0, columns which only contained missing val
我有一个包含 332 列的数据框。我想估算值以便能够使用 scikit-learn 的决策树分类器。我的问题是 imputer 函数的结果数据列只有 330。 from sklearn.preproc
我想在数据帧的所有 float64 列上使用 DataFrameMapper Imputer+Scaler 映射。我的代码适用于 StandardScaler,但当我添加 Imputer 时,映射器仅
import numpy as np import matplotlib.pyplot as plt import pandas as pd #Import Data set dataset= pd.
我是一名优秀的程序员,十分优秀!