2 回答

TA贡献1804条经验 获得超7个赞
你介意用一些你使用的数据的例子和给你问题的代码来更新你的问题 - 它会让你得到更好的答案!
从您的说法看来,适合的模型正在考虑您的目标变量是连续的而不是分类的(布尔值本质上是分类的 0 或 1)。MissForest 上的 API 文档说:
第一步涉及用初始猜测填充剩余的非候选列的任何缺失值,这是表示数值变量的列的列平均值和表示分类变量的列的列模式。请注意,分类变量需要在 imputer 的 fit() 方法调用期间明确标识(有关更多信息,请参阅 API)。
这意味着您应该cat_vars在拟合阶段指定:
fit(self, X, y=None, cat_vars=None):在 X 上拟合 imputer。
Parameters
----------
X : {array-like}, shape (n_samples, n_features)
Input data, where ``n_samples`` is the number of samples and
``n_features`` is the number of features.
cat_vars : int or array of ints, optional (default = None)
An int or an array containing column indices of categorical
variable(s)/feature(s) present in the dataset X.
``None`` if there are no categorical variables in the dataset.
Returns
-------
self : object
Returns self.
参考这里。
这意味着将使用类别而不是连续值进行估算。

TA贡献1824条经验 获得超6个赞
您有几种处理策略nan,让我们考虑一下这个玩具df:
import pandas as pd
import numpy as np
df = pd.DataFrame(
{
'column': [np.nan, True, np.nan]
}
)
print(df['column'])
>>>
0 NaN
1 True
2 NaN
Name: column, dtype: object
bool如果您负担得起使用损坏的数据(不建议),您可以简单地将列强制为一种类型:
print(df['column'].astype(bool))
>>>
0 True
1 True
2 True
Name: column, dtype: bool
您可以删除包含nan(最佳方法)的行:
print(df['column'].dropna())
>>>
1 True
Name: column, dtype: object
或者您可以将它们替换nan为默认值:
print(df['column'].fillna(False))
>>>
0 False
1 True
2 False
Name: column, dtype: bool
添加回答
举报