- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
所有特征都是 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/
在使用 GradientBoostingClassifiers 时,我试图获取模型预测的类的概率,我使用“predict_proba(X)”方法来预测这些类。但我想知道如何检查这个预测的准确性。 P
我已经回答了以下问题: how to extract decision rules of GradientBosstingClassifier How to extract the decision
我有一个非常不平衡的数据集,我需要在此基础上构建一个模型来解决分类问题。数据集有大约 30000 个样本,其中大约 1000 个样本标记为 -1-,其余标记为 0。我通过以下几行构建模型: X_tra
我正在使用 scikit-learn 的梯度提升树分类器,GradientBoostingClassifier .它使特征重要性得分在 feature_importances_ 中可用。如何计算这些特
我训练了一个 gradient boost classifier ,我想使用所示的 graphviz_exporter 工具对其进行可视化 here . 当我尝试时,我得到: AttributeErr
在 SciKit-Learn 中拟合 GradientBoostingClassifier 后,某些特征的重要性为零。 我的理解是,重要性为零意味着不会对此功能进行拆分。 如果我尝试使用不包含该功能的
为什么会这样 GradientBoostingClassifier(loss='ls') 失败: raise ValueError("``n_classes`` must be 1 for regre
我正在尝试使用 GradientBoostingClassifier 训练模型使用分类变量。 以下是原始代码示例,仅用于尝试将分类变量输入到 GradientBoostingClassifier 中。
有没有办法惩罚某个特征,使其不主导模型? (在 Salford Predictive Modeller 中,有一个名为“变量惩罚”的设置) 情况是,我有一个分类特征,我想将其包含在模型中,但我不想将其
我想从训练有素的梯度提升分类器(来自 sklearn)生成代码(现在是 Python,但最终是 C)。据我了解,该模型采用初始预测器,然后添加来自顺序训练的回归树的预测(按学习因子缩放)。所选择的类是
我正在尝试使用以下代码使用 joblib.dump 保存经过训练的 GradientBoostingClassifier: # use 90% of training data NI=int(len(
所有特征都是 float 数据类型,而有一些特征以 NaN 为主。我尝试通过 GradientBoostingClassifier 训练模型,如下所示。 train_x, test_x, train_
应用功能可以引用here 我的困惑更多来自this sample ,我在下面的代码片段中添加了一些打印以输出更多调试信息, grd = GradientBoostingClassifier(n_est
我尝试在 scikit-learn 中使用 GradientBoostingClassifier,它使用默认参数工作正常。但是,当我尝试用不同的分类器替换 BaseEstimator 时,它不起作用并
您好,我正在尝试将 VotingClassifier 与我的 GradientBoostingClassifier 一起使用,我在 GradientBoostingClassifier 周围放置了一个
我是一名优秀的程序员,十分优秀!