- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Pandas 数据框,它在特定列中有一些 NaN 值:
1291 NaN
1841 NaN
2049 NaN
Name: some column, dtype: float64
from sklearn.preprocessing import StandardScaler
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline
scaler = StandardScaler(with_mean = True)
imputer = SimpleImputer(strategy = 'median')
logistic = LogisticRegression()
pipe = Pipeline([('imputer', imputer),
('scaler', scaler),
('logistic', logistic)])
RandomizedSearchCV
时,我收到以下错误:
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
SimpleImputer
切换到(现已弃用)
Imputer
在管道中,管道在我的
RandomizedSearchCV
中工作得很好.我查看了文档,但似乎是
SimpleImputer
应该以(几乎)与
Imputer
完全相同的方式运行.行为有什么不同?如何在我的管道中使用输入器而不使用已弃用的
Imputer
?
最佳答案
make_pipeline 中的 SimpleImputer
preprocess_pipeline = make_pipeline(
FeatureUnion(transformer_list=[
('Handle numeric columns', make_pipeline(
ColumnSelector(columns=['Amount']),
SimpleImputer(strategy='constant', fill_value=0),
StandardScaler()
)),
('Handle categorical data', make_pipeline(
ColumnSelector(columns=['Type', 'Name', 'Changes']),
SimpleImputer(strategy='constant', missing_values=' ', fill_value='missing_value'),
OneHotEncoder(sparse=False)
))
])
)
('features', FeatureUnion ([
('Cat Columns', Pipeline([
('Category Extractor', TypeSelector(np.number)),
('Impute Zero', SimpleImputer(strategy="constant", fill_value=0))
])),
('Numerics', Pipeline([
('Numeric Extractor', TypeSelector("category")),
('Impute Missing', SimpleImputer(strategy="constant", fill_value='missing'))
]))
]))
关于scikit-learn - Sklearn SimpleImputer 在管道中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51741873/
我正在使用 scikit 库迈出第一步,发现自己仅需要回填数据框中的一些列。 我仔细阅读了 documentation但我仍然不知道如何实现这一目标。 为了更具体,假设我有: A = [[7,2,3]
我有一个 Pandas 数据框,它在特定列中有一些 NaN 值: 1291 NaN 1841 NaN 2049 NaN Name: some column, dtype: float64
我尝试: from sklearn.preprocessing import SimpleImputer imp = SimpleImputer() imputed = pd.DataFrame()
我正在关注 Aurelion Geron 的机器学习书籍。 我正在试验 ColumnTransformer 类。当我包含 SimplerImputer 时,会创建一个额外的列。我知道 SimplerI
我面临着创建管道来估算 (SI) 类别变量(例如颜色)然后 onehotencode (OHE) 2 个变量(例如颜色和星期几)的挑战。颜色用于 2 个步骤。 我想将 SI 和 OHE 放在 1 个
我无法理解流水线在 Sklearn 中的工作方式。以下是使用 titanic 数据集的示例。 data = pd.read_csv('datasets/train.csv') cat_attribs
我正在使用 PyCaret 并收到错误消息。 AttributeError: 'SimpleImputer' object has no attribute '_validate_data' 尝试创建
我使用 sklearn 来估算一些包含 NaN 值的时间序列。目前,我使用以下内容: from sklearn.preprocessing import Imputer imp = Imputer(m
在 python 的 sklearn 库中有两个类,它们做的事情大致相同:sklearn.preprocessing.Imputer 和 sklearn.impute.SimpleImputer 我发
我有一只 Pandas DataFrame包括一列文本,我想矢量化文本 使用 scikit-learn 的 CountVectorizer .但是,文本包含缺失值,因此我想 在矢量化之前输入一个常数值
sklearn提供了transform()方法来应用one-hot编码器。 要使用transform()方法,在调用transform()方法之前需要fit_transform(),否则 np.arr
在下面的笔记本中,使用 SimpleImputer 插入缺失值后,数据帧被转换为 numpy 数组,如何确保它的类型保持为数据帧本身? import pandas as pd df1 = pd.rea
我是一名优秀的程序员,十分优秀!