Passing categorical data to Sklearn Decision Tree

后端 未结 5 2051
攒了一身酷
攒了一身酷 2020-11-28 23:05

There are several posts about how to encode categorical data to Sklearn Decision trees, but from Sklearn documentation, we got these

Some advantages of d

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 23:50

    Sklearn Decision Trees do not handle conversion of categorical strings to numbers. I suggest you find a function in Sklearn (maybe this) that does so or manually write some code like:

    def cat2int(column):
        vals = list(set(column))
        for i, string in enumerate(column):
            column[i] = vals.index(string)
        return column
    

提交回复
热议问题