how do i convert a train data and train label matrices in matlab to libsvm 'train' file format?? i know how to interface libsvm with matlab. But i want to work in libsvm in cmd only. i get this error, i am clueless as why i get this error?

5 views (last 30 days)
matlab>> libsvmwrite('hamm15x7.train',trainlabel,traindata)
ERROR : can't open output file hamm15x7.train
  1 Comment
md.
md. on 24 Jun 2020
It depends on your data format. A simple way is to use libsvmwrite in the libsvm matlab/octave interface. Take a CSV (comma-separated values) file in UCI machine learning repository as an example. We download SPECTF.train. Labels are in the first column. The following steps produce a file in the libsvm format.
matlab> SPECTF = csvread('SPECTF.train'); % read a csv file
matlab> labels = SPECTF(:, 1); % labels from the 1st column
matlab> features = SPECTF(:, 2:end);
matlab> features_sparse = sparse(features); % features must be in a sparse matrix
matlab> libsvmwrite('SPECTFlibsvm.train', labels, features_sparse);
The tranformed data are stored in SPECTFlibsvm.train.
Alternatively, you can use convert.c to convert CSV format to libsvm format.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 5 Oct 2015
You could get that error if your current directory is one that you do not have permission to write. Use pwd to find out what directory you are in, and cd to one you can write to.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!