假设我的数据由水果组成,通过其颜色和形状以及具有任意值的更多特征(纹理大小果皮类型等)来描述。
我想使用 sklearn.tree 将我的数据拟合到决策树中
如何在 sklearn.tree 中构建决策树。 X 定义的样本和特征数组是什么,Y 是什么? 对于数据库,我使用 mongodb,因此数据集采用 json 格式:
{"_id":2323, "shape":"round", "color":[red,green], "texture":"A", "pill":"X", "more":[1,2,3]}
{"_id":2324, "shape":"round", "color":[orange], "texture":"C", "pill":"", "more":[1 ,2]}
是否有教程可以将数据拟合/转换为在 sklearn.tree 中构建决策树所需的 python 数据类型?
谢谢!
最佳答案
看看 documentation on feature extraction .
编辑:我刚刚注意到您的 json 构造中有嵌套结构。 DictVectorizer
和 FeatureHasher
类都期望平面字典作为输入。您可以展平自己的构造,例如:
{"_id": 2323, "shape": "round", "color/red": 1 "color/green": 1, "texture": "A",
"pill": "X", "more/1": 1, "more/2": 1, "more/3": 1}
然后在此类平面 Python 字典列表上调用 DictVectorizer
或 FeatureHasher
。
关于python - 如何将json数据定义为X和Y sklearn决策树数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15164506/