2 回答

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊
你介意用一些你使用的數(shù)據(jù)的例子和給你問(wèn)題的代碼來(lái)更新你的問(wèn)題 - 它會(huì)讓你得到更好的答案!
從您的說(shuō)法看來(lái),適合的模型正在考慮您的目標(biāo)變量是連續(xù)的而不是分類的(布爾值本質(zhì)上是分類的 0 或 1)。MissForest 上的 API 文檔說(shuō):
第一步涉及用初始猜測(cè)填充剩余的非候選列的任何缺失值,這是表示數(shù)值變量的列的列平均值和表示分類變量的列的列模式。請(qǐng)注意,分類變量需要在 imputer 的 fit() 方法調(diào)用期間明確標(biāo)識(shí)(有關(guān)更多信息,請(qǐng)參閱 API)。
這意味著您應(yīng)該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.
參考這里。
這意味著將使用類別而不是連續(xù)值進(jìn)行估算。

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
您有幾種處理策略nan,讓我們考慮一下這個(gè)玩具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如果您負(fù)擔(dān)得起使用損壞的數(shù)據(jù)(不建議),您可以簡(jiǎn)單地將列強(qiáng)制為一種類型:
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為默認(rèn)值:
print(df['column'].fillna(False))
>>>
0 False
1 True
2 False
Name: column, dtype: bool
添加回答
舉報(bào)