Menoufia University
Question
Asked 4 June 2013
How to convert libsvm file format into .csv format?
I want to use libsvm file in weka, but I am getting error with .libsvm format.
Most recent answer
how can you do it >>> my data is .mat
All Answers (24)
Mohammed VI Polytechnic University
You will have to read that using the read libsvmread and then save it into the format you need. Matlab would allow you to do this with a script of 3 or 4 lines. Do you use any scripting/programming language?
Cardiff Metropolitan University
I have used libsvmread in matlab, but i am not getting idea to convert this data in .csv format.
Mohammed VI Polytechnic University
read the data into a matrix and use dlmwrite to write the matrix to a file. CSV format is simply comma-separated values.
Cardiff Metropolitan University
I have read libSVM file using:
[lebel instance]=libsvmread(file)
But here my data is saved in two matrix:lebel, instance.
So how can i use it for dimwrite
because dimwrite syntax is: dlmwrite(filename, M)
Cardiff Metropolitan University
when i run:-
dimwrite('filename.csv', instance)
following error occur:
Undefined function 'dimwrite' for input arguments of type 'char'.
Herboristerie Silvati Incorporated
In MATLAB, use
data = [ double(label) double(instance) ]
to concatenate two matrices (of equal number of rows ; ) into one.
Cardiff Metropolitan University
Dear Matthias
After doing this following error is coming:
>> dlmwrite('FILENAME.csv',data)
error: Function is not defined for sparse inputs.
1 Recommendation
Mohammed VI Polytechnic University
Full(data) makes a sparse matrix full and sparce(data) does the opposite.
Cardiff Metropolitan University
it's done. But when i use this .csv file with weka, then it display error msg. Why?
De Montfort University
weka uses ARFF as because it contain defined attributes,.csv does not has this feature,weka needs labels for every nominal attributes,my suggestion u format ur data as in ARFF.
De Montfort University
weka uses ARFF as because it contain defined attributes,.csv does not has this feature,weka needs labels for every nominal attributes,my suggestion u format ur data as in ARFF
Mohammed VI Polytechnic University
Try using libsvm directly, if you get the same error let us know what the error is..
Cardiff Metropolitan University
Here snap of weka is attached with my problem, In this picture start button is not highlighted with .libsvm file created by me. But when i change attribute evaluator field then start button works.

Cardiff Metropolitan University
0.0 2:6.0 3:4.0 4:3.0 5:1169.0 6:4.0 7:4.0 8:4.0 9:2.0 11:4.0 13:67.0 14:2.0 15:1.0 16:2.0 17:2.0 18:1.0 19:1.0
1.0 1:1.0 2:48.0 3:2.0 4:3.0 5:5951.0 7:2.0 8:2.0 9:1.0 11:2.0 13:22.0 14:2.0 15:1.0 16:1.0 17:2.0 18:1.0
0.0 1:3.0 2:12.0 3:4.0 4:6.0 5:2096.0 7:3.0 8:2.0 9:2.0 11:3.0 13:49.0 14:2.0 15:1.0 16:1.0 17:1.0 18:2.0
0.0 2:42.0 3:2.0 4:2.0 5:7882.0 7:3.0 8:2.0 9:2.0 10:2.0 11:4.0 12:1.0 13:45.0 14:2.0 15:2.0 16:1.0 17:2.0 18:2.0
1.0 2:24.0 3:3.0 5:4870.0 7:2.0 8:3.0 9:2.0 11:4.0 12:3.0 13:53.0 14:2.0 15:2.0 16:2.0 17:2.0 18:2.0
0.0 1:3.0 2:36.0 3:2.0 4:6.0 5:9055.0 6:4.0 7:2.0 8:2.0 9:2.0 11:4.0 12:3.0 13:35.0 14:2.0 15:2.0 16:1.0 17:1.0 18:2.0 19:1.0
Mohammed VI Polytechnic University
I believe the labels(first number in each line) have to be integers.
This will not give you a runtime error but do you scale your data?
Cardiff Metropolitan University
I converted labels into integer, but it's not working. Please tell me all constrain for .csv file.
Related Publications
The census of population and dwellings undertaken by national state institutions world over at regular time intervals, is a fantastic source of information. However, there are major challenges to overcome when transforming the census data that usually consists of a vast number of attributes, into useful knowledge. In this paper, an artificial intel...
The goal in feature selection is to find a subset describing domain objects by resizing the data. Among the data embedded algorithms that perform non-linear dimension reduction, LLE stands by its effective mechanism to preserve local neighborhood structures. Here, we describe an adaptation of LLE for feature selection. We programmed the method as a...
In many machine learning classification problems, datasets are usually of high dimensionality and therefore require efficient and effective methods for identifying the relative importance of their attributes, eliminating the redundant and irrelevant ones. Due to the huge size of the search space of the possible solutions, the attribute subset evalu...