【问题标题】:Iterative Imputer by sklearn adding rows to Test data set during imputationsklearn 在插补期间向测试数据集添加行的迭代插补
【发布时间】:2020-04-08 21:16:32
【问题描述】:

我正在参与 Kaggle 上的 data sci 项目的数据,以了解有关 Python 的更多信息,并且正在使用 Iterative Imputer 来估计训练和测试数据集的年龄。

训练数据集891行,测试数据集418行。

在转换测试数据集以使用 imputer 与训练数据集拟合的值后,它添加行以使测试数据集也为 891 行。

非常欢迎任何帮助。

imp = IterativeImputer(max_iter=10, random_state = 1001, min_value=18, max_value=80, missing_values = np.nan)
features = ['Pclass', 'Age', 'SibSp','Parch', 'female', 'male', 'Cherbourg','Queenstown','Southampton']
train_df[features] = imp.fit(train_df[features])
#train_df[features] = imp.transform(train_df[features]) 
test_df[features] = imp.transform(test_df[features]) 

【问题讨论】:

    标签: python scikit-learn sklearn-pandas


    【解决方案1】:

    欢迎!文档说IterativeImputer().transform(X) 返回一个与X 形状相同的numpy 数组,所以也许检查一下你在方法中放了什么。在提出问题时,您可以尝试发布带有几行数据的最小可重现示例。这是一个提示链接:https://stackoverflow.com/help/minimal-reproducible-example

    【讨论】:

    • 托马斯,谢谢你的小费。你是对的:我检查并检查了我使用 test_df.shape 输入的内容,并且在此过程中我不小心将 train_df 应用到了 test_df。不用说,当我看到上面的这个特定代码时,我的数组比我要找的要大。只是需要让我的眼睛焕然一新。再次感谢。
    猜你喜欢
    • 2019-04-18
    • 2019-08-04
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 2014-11-30
    • 1970-01-01
    • 2013-06-17
    • 2021-10-15
    相关资源
    最近更新 更多