Converting CSV file to LIBSVM compatible data file using python

前端 未结 2 464
春和景丽
春和景丽 2020-12-31 23:20

I am doing a project using libsvm and I am preparing my data to use the lib. How can I convert CSV file to LIBSVM compatible data?

CSV File: https:

2条回答
  •  既然无缘
    2020-12-31 23:55

    You can use csv2libsvm.py to convert csv to libsvm data

    python csv2libsvm.py iris.csv libsvm.data 4 True
    

    where 4 means target index, and True means csv has a header.

    Finally, you can get libsvm.data as

    0 1:5.1 2:3.5 3:1.4 4:0.2
    0 1:4.9 2:3.0 3:1.4 4:0.2
    0 1:4.7 2:3.2 3:1.3 4:0.2
    0 1:4.6 2:3.1 3:1.5 4:0.2
    ...
    

    from iris.csv

    150,4,setosa,versicolor,virginica
    5.1,3.5,1.4,0.2,0
    4.9,3.0,1.4,0.2,0
    4.7,3.2,1.3,0.2,0
    4.6,3.1,1.5,0.2,0
    ...
    

提交回复
热议问题