我有一个在weka中运行良好的数据集。它有很多缺失值由'?'表示。使用决策树,我能够处理缺失的值。
但是,在sci-kit学习中,我发现估算器不能用于缺少值的数据。我可以使用替代库来支持这个吗?
否则,有没有办法在sci-kit学习中解决这个问题?
答案 0 :(得分:0)
py-earth包支持缺少数据。它仍在开发中,还没有在pypi上,但它在这一点上非常实用且经过充分测试,并且与scikit-learn很好地交互。如this paper中所述处理缺失。它不假设随意丢失,实际上缺失被视为具有潜在预测性。重要的假设是,训练数据中缺失的分布必须与您在运行中使用模型的任何数据相同。
py-earth提供的Earth
类是回归量。要创建分类器,您需要将其放在带有其他scikit-learn分类器的管道中(我通常使用LogisticRegression
)。这是一个例子:
from pyearth import Earth
from sklearn.linear_model.logistic import LogisticRegression
from sklearn.pipeline import Pipeline
# X and y are some training data (numpy arrays, pandas DataFrames, or
# similar) and X may have some values that are missing (nan, None, or
# some other standard signifier of missingness)
from your_data import X, y
# Create an Earth based classifer that accepts missing data
earth_classifier = Pipeline([('earth', Earth(allow_missing=True)),
('logistic', LogisticRegression())])
# Fit on the training data
earth_classifier.fit(X, y)
Earth
模型以一种很好的方式处理缺失,而LogisticRegression
只能看到转化后的数据来自Earth.transform
。
免责声明:我是py-earth的作者。