svm - How to implement data I have to svmtrain() function in MATLAB? -
i have write script using matlab classify data.
my data consists of 1051 web pages (rows) , 11000+ words (columns). holding word occurences in matrix each page. first 230 rows computer science course (to labeled +1) , remaining 821 not (to labeled -1). going label few part of these rows (say 30 rows) myself. svm label remaining unlabeled rows.
i have found solve problem using matlab's svmtrain()
, svmclassify()
methods. first need create svmstruct
.
svmstruct = svmtrain(training,group)
then need use
group = svmclassify(svmstruct,sample)
but point not know training
, group
are. group
mathworks says:
grouping variable, can categorical, numeric, or logical vector, cell vector of strings, or character matrix each row representing class label. each element of group specifies group of corresponding row of training. group should divide training 2 groups. group has same number of elements there rows in training. svmtrain treats each nan, empty string, or 'undefined' in group missing value, , ignores corresponding row of training.
and training
said that:
matrix of training data, each row corresponds observation or replicate, , each column corresponds feature or variable. svmtrain treats nans or empty strings in training missing values , ignores corresponding rows of group.
i want know how can adopt data training
, group
? need (at least) little code sample.
edit
what did not understand in order have svmstruct
have run
svmstruct = svmtrain(training, group);
and in order have group have run
group = svmclassify(svmstruct,sample);
also still did not sample
should like?
i confused.
training
matrix 1051 rows (the webpages/training instances) , 11000 columns (the features/words). i'm assuming want test existence of each word on webpage? in case make entry of matrix 1
if word exists given webpage , 0
if not.
you initialize matrix training = zeros(1051,11000);
filling entries you, presumably done other code you've written.
group
1-d column vector 1 entry every training instance (webpage) tells of 2 classes webpage belongs to. in case make first 230 entries "+1" computer science , remaining 821 entries "-1" not.
group = zeros(1051,1); % gives matrix of zeros 1051 rows , 1 column group(1:230) = 1; % set first 230 entries +1 group(231:end) = -1; % set rest -1
Comments
Post a Comment