gpt4 book ai didi

python - 如何处理 sklearn 中 GradientBoostingClassifier 中的大量缺失值

转载 作者:太空狗 更新时间:2023-10-30 02:54:01 25 4
gpt4 key购买 nike

所有特征都是 float 数据类型,而有一些特征以 NaN 为主。我尝试通过 GradientBoostingClassifier 训练模型,如下所示。

train_x, test_x, train_y, test_y = train_test_split(features[feature_headers], features[target_header], test_size=0.33, random_state=int(time.time()))
clf = GradientBoostingClassifier(random_state=int(time.time()), learning_rate=0.1, max_leaf_nodes=None, min_samples_leaf=1, n_estimators=300, min_samples_split=2, max_features=None)
clf.fit(train_x, train_y)

但是会抛出错误:

ValueError: Input contains NaN, infinity or a value too large for dtype('float32').

我无法使用某些插补方法用均值、中位数或 most_frequent 填充 NaN,因为从数据的角度来看它没有任何意义。有没有更好的方法让分类器识别 NaN 并将其也视为指示性特征?非常感谢。

最佳答案

您将必须执行数据清理。为此,您需要查看要包含在训练数据集中的所有。对于 float ,您可以将所有 null 值替换为零

df.col1 = df.col1.fillna(0)

对于字符串,您可以将其替换为默认值。

df.col2 = df.DISTANCE_GROUP.fillna('')

现在,如果您想放置平均值 或一些趋势值,您可以使用相同的学习算法来预测缺失值并进行填充。为了运行该算法,首先替换空值,然后可以用更准确的预测值进行更改。

Note: Any learning algorithm can't run with null values.

关于python - 如何处理 sklearn 中 GradientBoostingClassifier 中的大量缺失值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47484481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com