【问题标题】:How to define json data as X and Y sklearn decision tree arrays如何将 json 数据定义为 X 和 Y sklearn 决策树数组
【发布时间】:2013-02-16 08:29:48
【问题描述】:

假设我的数据由水果组成,由它们的颜色和形状以及更多具有任意值的特征(纹理大小、果皮类型等)来描述。

我想使用 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 数据类型的教程?

谢谢!

【问题讨论】:

    标签: python json scikit-learn decision-tree


    【解决方案1】:

    看看documentation on feature extraction

    编辑:我刚刚注意到您的 json 结构中有嵌套结构。 DictVectorizerFeatureHasher 类都期望平面字典作为输入。你可以扁平化你自己的构造,例如:

    {"_id": 2323, "shape": "round", "color/red": 1 "color/green": 1, "texture": "A",
     "pill": "X", "more/1": 1, "more/2": 1, "more/3": 1}
    

    然后在此类平面 python dicts 列表上调用 DictVectorizerFeatureHasher

    【讨论】:

      猜你喜欢
      • 2018-06-23
      • 1970-01-01
      • 2017-10-11
      • 2016-11-01
      • 2021-10-07
      • 2016-05-06
      • 2018-09-15
      • 2019-03-04
      • 2015-06-27
      相关资源
      最近更新 更多