![](/img/trans.png)
[英]How to handle categorical variables in sklearn GradientBoostingClassifier?
[英]How to handle lots of missing values in GradientBoostingClassifier in sklearn
所有特征都是浮点数据类型,而有一些特征具有显着量的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:输入包含NaN,无穷大或对于dtype('float32')而言太大的值。
我不能使用一些Imputation方法用mean,median或most_frequent填充NaN,因为从数据的角度来看它没有任何意义。 有没有更好的方法让分类器识别NaN并将其视为指示性功能? 非常感谢。
您必须执行数据清理。 为此,您需要查看要包含在训练数据集中的所有columns
。 对于float,您可以将所有null
值替换为零
df.col1 = df.col1.fillna(0)
对于字符串,您可以将其替换为默认值。
df.col2 = df.DISTANCE_GROUP.fillna('')
现在,如果要放置average
或某些趋势值,可以使用相同的学习算法来预测缺失值并填充。 为了运行算法,首先替换空值,然后可以使用更准确的预测值进行更改。
注意:任何学习算法都不能使用空值运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.