How to train an SVM classifier
4 ビュー (過去 30 日間)
古いコメントを表示
I have read the following theory on SVM in Matlab help:
Training an SVM Classifier
Train, and optionally cross validate, an SVM classifier using fitcsvm. The most common syntax is:
SVMModel = fitcsvm(X,Y,'KernelFunction','rbf','Standarize',true,'ClassNames',{'negClass','posClass'}); The inputs are:
X — Matrix of predictor data, where each row is one observation, and each column is one predictor.
Y — Array of class labels with each row corresponding to the value of the corresponding row in X. Y can be a character array, categorical, logical or numeric vector, or vector cell array of strings. Column vector with each row corresponding to the value of the corresponding row in X. Y can be a categorical or character array, logical or numeric vector, or cell array of strings.
KernelFunction — The default value is 'linear' for two-class learning, which separates the data by a hyperplane. The value 'rbf' is the default for one-class learning, and uses a Gaussian radial basis function. An important step to successfully train an SVM classifier is to choose an appropriate kernel function.
Standardize — Flag indicating whether the software should standardize the predictors before training the classifier.
ClassNames — Cell array of strings indicating which class is the negative class, and which is the positive class. The negative class is in the first cell (negClass), and the positive class is in the second cell (posClass). It is good practice to specify the class names, especially if you are comparing the performance of different classifiers.
The resulting, trained model (SVMModel) contains the optimized parameters from the SVM algorithm, enabling you to classify new data.
For more name-value pairs you can use to control the training, see the fitcsvm reference page.
Classifying New Data with an SVM Classifier
Classify new data using predict. The syntax for classifying new data using a trained SVM classifier (SVMModel) is:
[label,score] = predict(SVMModel,newX);
The resulting vector, label, represents the classification of each row in X. score is an n-by-2 matrix of soft scores. Each row corresponds to a row in X, which is a new observation. The first column contains the scores for the observations being classified in the negative class, and the second column contains the scores observations being classified in the positive class.
Acorrding to the theory, I generated my Predictor Matrix X and my class label Y.
X = [2.1805e-007 0.0186 1.4810e+006 0.0043 0.9895 ; 2.1852e-007 0.0064 1.5349e+006 0.0043 0.9899 ; 2.1805e-007 0.0186 1.4810e+006 0.0043 0.9895 ; 2.1966e-007 0.0224 1.4480e+006 0.0044 0.9909 ; 2.335e-007 0.0099 1.4135e+006 0.0042 0.9985 ; 2.2724e-007 0.0172 1.4265e+006 0.0044 0.9959 ; 2.3093e-007 0.0070 1.5294e+006 0.0043 0.9976 ; 2.2750e-007 0.0247 1.4833e+006 0.0042 0.9967 ; 2.3222e-007 0.0109 1.6049e+006 0.0043 0.9980 ; 2.3129e-007 0.0195 1.6220e+006 0.0043 0.9977 ; 1.0036e-004 0.0900 1.0062e+005 0.0202 0.1554 ; 1.0624e-004 -0.0056 1.2374e+005 0.0217 0.1456 ; 2.4432e-004 -0.0176 9.8072e+004 0.0227 0.0758 ; 4.5775e-005 0.0581 1.1252e+006 0.0015 0.0267] ;
Y = [1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1; 1 ; 1 ; 1 ; 0 ; 0 ; 0 ; 0 ; 0] ;
and used the following instructions for training SVM classifier and then testing it with a new input newX.
SVMModel = fitcsvm(M,N,'KernelFunction','rbf','Standarize',true,'ClassNames',{'negClass','posClass'}) [label,score] = predict(SVMModel,newX);
However i am getting an error:
??? Undefined function or method 'fitcsvm' for input arguments of type 'cell'.
Error in ==> maculaedema at 171 SVMModel = fitcsvm(X,Y,'KernelFunction','rbf','Standarize',true,'ClassNames',{'negClass','posClass'}) >>
Can anyone tell me why am i getting this error.......
0 件のコメント
採用された回答
Alan Weiss
2014 年 7 月 2 日
fitcsvm was introduced in R2014a. Perhaps your MATLAB version is older than that?
If you have Statistics Toolbox version R2013a or R2013b you can use svmtrain. If your MATLAB version is older than that, you need Bioinformatics Toolbox to access svmtrain.
Alan Weiss
MATLAB mathematical toolbox documentation
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Classification Learner App についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!