所有的特征都是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').
我不能使用一些插补方法来填充平均数、中位数或最频繁的NaN,因为从数据的角度来看,这没有任何意义。有没有更好的方法让分类器识别NaN并将其作为指示性特征来处理?谢谢。在
您必须执行数据清理。为此,您需要查看要在训练数据集中包括哪些
columns
。对于float,可以将所有null
值替换为零对于字符串,可以将其替换为默认值。在
^{pr2}$现在,如果您想放置
average
或一些趋势值,您可以使用相同的学习算法来预测缺失值并填充。为了运行该算法,首先替换空值,然后可以用更精确的预测值进行更改。在xgboost.XGBClassifier
句柄np.nan
没有插补see here。在xgboost
有一个易于使用的sklearn
api look at the documentation。在xgboost.XGBClassifier
基本上是非常接近的形式GradientBoostingClassifier
,两者都是用于分类的梯度提升方法。有关示例here,请参阅。在相关问题 更多 >
编程相关推荐