Skip to content
Advertisement

How to load SVMlight format files in compressed form to pandas?

I have data in SVMlight format (label feature1:value1 feature2:v2 …) as such

JavaScript

I tried sklearn.load_svmlight_file but it doesn’t seem to work with categorical string features and labels. I am trying to store it into pandas DataFrame. Any pointers would be appreciated.

Advertisement

Answer

You can do it by hand… One way you can convert the file you want in a DataFrame:

JavaScript

The result DataFrame with your example file:

JavaScript

enter image description here

Advertisement