支持向量機可以用于分類、回歸與異常點檢測,它有以下優(yōu)勢:
成都創(chuàng)新互聯(lián)于2013年成立,先為永勝等服務(wù)建站,永勝等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為永勝企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
1、對高維數(shù)據(jù)集十分有效。
2、當(dāng)pn時,依然有效。
3、高效利用內(nèi)存。
4、不同的核函數(shù)與決策函數(shù)一一對應(yīng)。
缺點如下:
1、當(dāng)pn時,需要合理選用核函數(shù)以避免過擬合。
2、由于支持向量機不直接提供概率估計,需要經(jīng)過五折交叉驗證計算得到,所以它較慢。
SVC、NuSVC和LinearSVC能夠?qū)崿F(xiàn)多元分類。SVC與NuSVC十分相似,不同之處在于NuSVC引入了一個新的超參數(shù)v,它可以控制支持向量的數(shù)量和訓(xùn)練誤差。LinearSVC是另一個實現(xiàn)線性核函數(shù)的支持向量分類,所以它不接受關(guān)鍵詞kernel,也沒有所謂的支持向量。
支持向量的解釋:支持向量本質(zhì)上就是一個向量,而且是離間隔邊界最近的向量,也就是這些向量支撐了整個間隔邊界,支持向量的名字由來就是這樣。
多元分類在分類中主要有兩種方法:one-vs-one和one-vs-rest。
one-vs-one:假設(shè)有n個類別,則會針對兩兩類別建立二項分類器,得到k=n*(n-1)/2個分類器。對新數(shù)據(jù)進行分類時,依次使用這k個分類器進行分類,每次分類相當(dāng)于一次投票,分類結(jié)果是哪個就相當(dāng)于對哪個類投了一票。在使用全部k個分類器進行分類后,相當(dāng)于進行了k次投票,選擇得票最多的那個類作為最終分類結(jié)果。
one-vs-rest:假設(shè)有n個類別,那么就會建立n個二項分類器,每個分類器針對其中一個類別和剩余類別進行分類。進行預(yù)測時,利用這n個二項分類器進行分類,得到數(shù)據(jù)屬于當(dāng)前類的概率,選擇其中概率最大的一個類別作為最終的預(yù)測結(jié)果。
其中,one-vs-rest更加受到青睞,因為它更快并且結(jié)果也很不錯。
在內(nèi)核嶺回歸中我們有談到過支持向量回歸,支持向量分類與支持向量回歸都是只依賴于訓(xùn)練集的子集,因為構(gòu)建模型的代價函數(shù)忽略任何接近于模型預(yù)測的訓(xùn)練數(shù)據(jù)。支持向量回歸也有三種不同的形式:SVR、NuSVR和LinearSVR。
OneClassSVM實現(xiàn)了一個用于無監(jiān)督的孤立點檢測。
支持向量機是個強大的工具,不過它的計算和存儲空間要求也會隨著要訓(xùn)練向量的數(shù)目增加而快速增加。?SVM的核心是一個二次規(guī)劃問題,是將支持向量和訓(xùn)練數(shù)據(jù)的其余部分分離開來。一般情況下復(fù)雜度為 ~ 。
懲罰系數(shù)C的設(shè)置:C定義了你對噪聲的重視程度,如果數(shù)據(jù)中有很多噪聲,我們應(yīng)該減小C,防止模型過擬合。
gamma的設(shè)置:gamma?定義了單一 訓(xùn)練樣本能起到多大的影響,這樣就會導(dǎo)致只有某些訓(xùn)練樣本就能占領(lǐng)主導(dǎo)地位,對于訓(xùn)練集可能效果會很好,但是對于測試集效果很差,即會導(dǎo)致過擬合,降低gamma能有效降低過擬合的風(fēng)險,與C一樣。
推薦一個網(wǎng)站,作者將SVM講述的很好: SVM入門(一)至(三)Refresh - Jasper's Java Jacal - BlogJava
參考:《Scikit-Learn官方API》
如有錯誤,請指正;如有疑問,請留言。
LIBSVM的簡單介紹 2006-09-20 15:59:48
大 中 小
1. LIBSVM 軟件包簡介
LIBSVM 是臺灣大學(xué)林智仁(Chih-Jen Lin)博士等開發(fā)設(shè)計的一個操作簡單、易于使用、快速有效的通用SVM 軟件包,可以解決分類問題(包括C- SVC、n - SVC )、回歸問題(包括e - SVR、n - SVR )以及分布估計(one-class-SVM )等問題,提供了線性、多項式、徑向基和S形函數(shù)四種常用的核函數(shù)供選擇,可以有效地解決多類問題、交叉驗證選擇參數(shù)、對不平衡樣本加權(quán)、多類問題的概率估計等。LIBSVM 是一個開源的軟件包,需要者都可以免費的從作者的個人主頁
處獲得。他不僅提供了LIBSVM的C++語言的算法源代碼,還提供了Python、Java、R、MATLAB、Perl、Ruby、LabVIEW以及C#.net 等各種語言的接口,可以方便的在Windows 或UNIX 平臺下使用。另外還提供了WINDOWS 平臺下的可視化操作工具SVM-toy,并且在進行模型參數(shù)選擇時可以繪制出交叉驗證精度的等高線圖。
2. LIBSVM 使用方法簡介
LibSVM是以源代碼和可執(zhí)行文件兩種方式給出的。如果是Windows系列操作系統(tǒng),可以直接使用軟件包提供的程序,也可以進行修改編譯;如果是Unix類系統(tǒng),必須自己編譯。
LIBSVM 在給出源代碼的同時還提供了Windows操作系統(tǒng)下的可執(zhí)行文件,包括:進行支持向量機訓(xùn)練的svmtrain.exe;根據(jù)已獲得的支持向量機模型對數(shù)據(jù)集進行預(yù)測的svmpredict.exe;以及對訓(xùn)練數(shù)據(jù)與測試數(shù)據(jù)進行簡單縮放操作的svmscale.exe。它們都可以直接在DOS 環(huán)境中使用。如果下載的包中只有C++的源代碼,則也可以自己在VC等軟件上編譯生成可執(zhí)行文件。
3. LIBSVM 使用的一般步驟是:
1) 按照LIBSVM軟件包所要求的格式準(zhǔn)備數(shù)據(jù)集;
2) 對數(shù)據(jù)進行簡單的縮放操作;
3) 考慮選用RBF 核函數(shù);
4) 采用交叉驗證選擇最佳參數(shù)C與g ;
5) 采用最佳參數(shù)C與g 對整個訓(xùn)練集進行訓(xùn)練獲取支持向量機模型;
6) 利用獲取的模型進行測試與預(yù)測。
4. LIBSVM使用的數(shù)據(jù)格式
1)訓(xùn)練數(shù)據(jù)和檢驗數(shù)據(jù)文件格式如下:
label index1:value1 index2:value2 ...
其中l(wèi)abel 是訓(xùn)練數(shù)據(jù)集的目標(biāo)值,對于分類,它是標(biāo)識某類的整數(shù)(支持多個類);對于回歸,是任意實數(shù)。index 是以1開始的整數(shù),可以是不連續(xù)的;value為實數(shù),也就是我們常說的自變量。檢驗數(shù)據(jù)文件中的label只用于計算準(zhǔn)確度或誤差,如果它是未知的,只需用一個數(shù)填寫這一欄,也可以空著不填。
在程序包中,還包括有一個訓(xùn)練數(shù)據(jù)實例:heart_scale,方便參考數(shù)據(jù)文件格式以及練習(xí)使用軟件??梢跃帉懶〕绦颍瑢⒆约撼S玫臄?shù)據(jù)格式轉(zhuǎn)換成這種格式
2)Svmtrain和Svmpredict的用法
LIBSVM軟件提供的各種功能都是DOS命令執(zhí)行方式。我們主要用到兩個程序,svmtrain(訓(xùn)練建模)和svmpredict(使用已有的模型進行預(yù)測),下面分別對這兩個程序的使用方法、各參數(shù)的意義以及設(shè)置方法做一個簡單介紹:
(1)Svmtrain的用法:
svmtrain [options] training_set_file [model_file]
Options:可用的選項即表示的涵義如下
-s svm類型:SVM設(shè)置類型(默認(rèn)0)
0 -- C-SVC
1 --v-SVC
2 – 一類SVM
3 -- e -SVR
4 -- v-SVR
-t 核函數(shù)類型:核函數(shù)設(shè)置類型(默認(rèn)2)
0 – 線性:u'v
1 – 多項式:(r*u'v + coef0)^degree
2 – RBF函數(shù):exp(-r|u-v|^2)
3 –sigmoid:tanh(r*u'v + coef0)
-d degree:核函數(shù)中的degree設(shè)置(默認(rèn)3)
-g 函數(shù)設(shè)置(默認(rèn)1/ k)?r(gama):核函數(shù)中的
-r coef0:核函數(shù)中的coef0設(shè)置(默認(rèn)0)
?-c cost:設(shè)置C-SVC, -SVR的參數(shù)(默認(rèn)1)?-SVR和
- SVR的參數(shù)(默認(rèn)0.5)?-SVC,一類SVM和?-n nu:設(shè)置
-SVR?-p e:設(shè)置的值(默認(rèn)0.1)?中損失函數(shù)
-m cachesize:設(shè)置cache內(nèi)存大小,以MB為單位(默認(rèn)40)
-e :設(shè)置允許的終止判據(jù)(默認(rèn)0.001)?
-h shrinking:是否使用啟發(fā)式,0或1(默認(rèn)1)
-wi C(C-SVC中的C)(默認(rèn)1)?weight:設(shè)置第幾類的參數(shù)C為weight
-v n: n-fold交互檢驗?zāi)J?/p>
其中-g選項中的k是指輸入數(shù)據(jù)中的屬性數(shù)。option -v 隨機地將數(shù)據(jù)剖分為n部分并計算交互檢驗準(zhǔn)確度和均方根誤差。以上這些參數(shù)設(shè)置可以按照SVM的類型和核函數(shù)所支持的參數(shù)進行任意組合,如果設(shè)置的參數(shù)在函數(shù)或SVM類型中沒有也不會產(chǎn)生影響,程序不會接受該參數(shù);如果應(yīng)有的參數(shù)設(shè)置不正確,參數(shù)將采用默認(rèn)值。training_set_file是要進行訓(xùn)練的數(shù)據(jù)集;model_file是訓(xùn)練結(jié)束后產(chǎn)生的模型文件,文件中包括支持向量樣本數(shù)、支持向量樣本以及l(fā)agrange系數(shù)等必須的參數(shù);該參數(shù)如果不設(shè)置將采用默認(rèn)的文件名,也可以設(shè)置成自己慣用的文件名。
(2)Svmpredict的用法:
svmpredict test_file model_file output_file
model_file 是由svmtrain產(chǎn)生的模型文件;test_file是要進行預(yù)測的數(shù)據(jù)文件;Output_file是svmpredict的輸出文件。svm-predict沒有其它的選項。
下面是具體的使用例子
svmtrain -s 0 -c 1000 -t 1 -g 1 -r 1 -d 3 data_file
訓(xùn)練一個由多項式核(u'v+1)^3和C=1000組成的分類器。
svmtrain -s 1 -n 0.1 -t 2 -g 0.5 -e 0.00001 data_file =?-SVM (?在RBF核函數(shù)exp(-0.5|u-v|^2)和終止允許限0.00001的條件下,訓(xùn)練一個 0.1)分類器。 svmtrain -s 3 -p 0.1 -t 0 -c 10 data_file =?以線性核函數(shù)u'v和C=10及損失函數(shù) 0.1求解SVM回歸。
如果是7.0以上版本
edit svmtrain
edit svmclassify
edit svmpredict
function [svm_struct, svIndex] = svmtrain(training, groupnames, varargin)
%SVMTRAIN trains a support vector machine classifier
%
% SVMStruct = SVMTRAIN(TRAINING,GROUP) trains a support vector machine
% classifier using data TRAINING taken from two groups given by GROUP.
% SVMStruct contains information about the trained classifier that is
% used by SVMCLASSIFY for classification. GROUP is a column vector of
% values of the same length as TRAINING that defines two groups. Each
% element of GROUP specifies the group the corresponding row of TRAINING
% belongs to. GROUP can be a numeric vector, a string array, or a cell
% array of strings. SVMTRAIN treats NaNs or empty strings in GROUP as
% missing values and ignores the corresponding rows of TRAINING.
%
% SVMTRAIN(...,'KERNEL_FUNCTION',KFUN) allows you to specify the kernel
% function KFUN used to map the training data into kernel space. The
% default kernel function is the dot product. KFUN can be one of the
% following strings or a function handle:
%
% 'linear' Linear kernel or dot product
% 'quadratic' Quadratic kernel
% 'polynomial' Polynomial kernel (default order 3)
% 'rbf' Gaussian Radial Basis Function kernel
% 'mlp' Multilayer Perceptron kernel (default scale 1)
% function A kernel function specified using @,
% for example @KFUN, or an anonymous function
%
% A kernel function must be of the form
%
% function K = KFUN(U, V)
%
% The returned value, K, is a matrix of size M-by-N, where U and V have M
% and N rows respectively. If KFUN is parameterized, you can use
% anonymous functions to capture the problem-dependent parameters. For
% example, suppose that your kernel function is
%
% function k = kfun(u,v,p1,p2)
% k = tanh(p1*(u*v')+p2);
%
% You can set values for p1 and p2 and then use an anonymous function:
% @(u,v) kfun(u,v,p1,p2).
%
% SVMTRAIN(...,'POLYORDER',ORDER) allows you to specify the order of a
% polynomial kernel. The default order is 3.
%
% SVMTRAIN(...,'MLP_PARAMS',[P1 P2]) allows you to specify the
% parameters of the Multilayer Perceptron (mlp) kernel. The mlp kernel
% requires two parameters, P1 and P2, where K = tanh(P1*U*V' + P2) and P1
% 0 and P2 0. Default values are P1 = 1 and P2 = -1.
%
% SVMTRAIN(...,'METHOD',METHOD) allows you to specify the method used
% to find the separating hyperplane. Options are
%
% 'QP' Use quadratic programming (requires the Optimization Toolbox)
% 'LS' Use least-squares method
%
% If you have the Optimization Toolbox, then the QP method is the default
% method. If not, the only available method is LS.
%
% SVMTRAIN(...,'QUADPROG_OPTS',OPTIONS) allows you to pass an OPTIONS
% structure created using OPTIMSET to the QUADPROG function when using
% the 'QP' method. See help optimset for more details.
%
% SVMTRAIN(...,'SHOWPLOT',true), when used with two-dimensional data,
% creates a plot of the grouped data and plots the separating line for
% the classifier.
%
% Example:
% % Load the data and select features for classification
% load fisheriris
% data = [meas(:,1), meas(:,2)];
% % Extract the Setosa class
% groups = ismember(species,'setosa');
% % Randomly select training and test sets
% [train, test] = crossvalind('holdOut',groups);
% cp = classperf(groups);
% % Use a linear support vector machine classifier
% svmStruct = svmtrain(data(train,:),groups(train),'showplot',true);
% classes = svmclassify(svmStruct,data(test,:),'showplot',true);
% % See how well the classifier performed
% classperf(cp,classes,test);
% cp.CorrectRate
%
% See also CLASSIFY, KNNCLASSIFY, QUADPROG, SVMCLASSIFY.
% Copyright 2004 The MathWorks, Inc.
% $Revision: 1.1.12.1 $ $Date: 2004/12/24 20:43:35 $
% References:
% [1] Kecman, V, Learning and Soft Computing,
% MIT Press, Cambridge, MA. 2001.
% [2] Suykens, J.A.K., Van Gestel, T., De Brabanter, J., De Moor, B.,
% Vandewalle, J., Least Squares Support Vector Machines,
% World Scientific, Singapore, 2002.
% [3] Scholkopf, B., Smola, A.J., Learning with Kernels,
% MIT Press, Cambridge, MA. 2002.
%
% SVMTRAIN(...,'KFUNARGS',ARGS) allows you to pass additional
% arguments to kernel functions.
% set defaults
plotflag = false;
qp_opts = [];
kfunargs = {};
setPoly = false; usePoly = false;
setMLP = false; useMLP = false;
if ~isempty(which('quadprog'))
useQuadprog = true;
else
useQuadprog = false;
end
% set default kernel function
kfun = @linear_kernel;
% check inputs
if nargin 2
error(nargchk(2,Inf,nargin))
end
numoptargs = nargin -2;
optargs = varargin;
% grp2idx sorts a numeric grouping var ascending, and a string grouping
% var by order of first occurrence
[g,groupString] = grp2idx(groupnames);
% check group is a vector -- though char input is special...
if ~isvector(groupnames) ~ischar(groupnames)
error('Bioinfo:svmtrain:GroupNotVector',...
'Group must be a vector.');
end
% make sure that the data is correctly oriented.
if size(groupnames,1) == 1
groupnames = groupnames';
end
% make sure data is the right size
n = length(groupnames);
if size(training,1) ~= n
if size(training,2) == n
training = training';
else
error('Bioinfo:svmtrain:DataGroupSizeMismatch',...
'GROUP and TRAINING must have the same number of rows.')
end
end
% NaNs are treated as unknown classes and are removed from the training
% data
nans = find(isnan(g));
if length(nans) 0
training(nans,:) = [];
g(nans) = [];
end
ngroups = length(groupString);
if ngroups 2
error('Bioinfo:svmtrain:TooManyGroups',...
'SVMTRAIN only supports classification into two groups.\nGROUP contains %d different groups.',ngroups)
end
% convert to 1, -1.
g = 1 - (2* (g-1));
% handle optional arguments
if numoptargs = 1
if rem(numoptargs,2)== 1
error('Bioinfo:svmtrain:IncorrectNumberOfArguments',...
'Incorrect number of arguments to %s.',mfilename);
end
okargs = {'kernel_function','method','showplot','kfunargs','quadprog_opts','polyorder','mlp_params'};
for j=1:2:numoptargs
pname = optargs{j};
pval = optargs{j+1};
k = strmatch(lower(pname), okargs);%#ok
if isempty(k)
error('Bioinfo:svmtrain:UnknownParameterName',...
'Unknown parameter name: %s.',pname);
elseif length(k)1
error('Bioinfo:svmtrain:AmbiguousParameterName',...
'Ambiguous parameter name: %s.',pname);
else
switch(k)
case 1 % kernel_function
if ischar(pval)
okfuns = {'linear','quadratic',...
'radial','rbf','polynomial','mlp'};
funNum = strmatch(lower(pval), okfuns);%#ok
if isempty(funNum)
funNum = 0;
end
switch funNum %maybe make this less strict in the future
case 1
kfun = @linear_kernel;
case 2
kfun = @quadratic_kernel;
case {3,4}
kfun = @rbf_kernel;
case 5
kfun = @poly_kernel;
usePoly = true;
case 6
kfun = @mlp_kernel;
useMLP = true;
otherwise
error('Bioinfo:svmtrain:UnknownKernelFunction',...
'Unknown Kernel Function %s.',kfun);
end
elseif isa (pval, 'function_handle')
kfun = pval;
else
error('Bioinfo:svmtrain:BadKernelFunction',...
'The kernel function input does not appear to be a function handle\nor valid function name.')
end
case 2 % method
if strncmpi(pval,'qp',2)
useQuadprog = true;
if isempty(which('quadprog'))
warning('Bioinfo:svmtrain:NoOptim',...
'The Optimization Toolbox is required to use the quadratic programming method.')
useQuadprog = false;
end
elseif strncmpi(pval,'ls',2)
useQuadprog = false;
else
error('Bioinfo:svmtrain:UnknownMethod',...
'Unknown method option %s. Valid methods are ''QP'' and ''LS''',pval);
end
case 3 % display
if pval ~= 0
if size(training,2) == 2
plotflag = true;
else
warning('Bioinfo:svmtrain:OnlyPlot2D',...
'The display option can only plot 2D training data.')
end
end
case 4 % kfunargs
if iscell(pval)
kfunargs = pval;
else
kfunargs = {pval};
end
case 5 % quadprog_opts
if isstruct(pval)
qp_opts = pval;
elseif iscell(pval)
qp_opts = optimset(pval{:});
else
error('Bioinfo:svmtrain:BadQuadprogOpts',...
'QUADPROG_OPTS must be an opts structure.');
end
case 6 % polyorder
if ~isscalar(pval) || ~isnumeric(pval)
error('Bioinfo:svmtrain:BadPolyOrder',...
'POLYORDER must be a scalar value.');
end
if pval ~=floor(pval) || pval 1
error('Bioinfo:svmtrain:PolyOrderNotInt',...
'The order of the polynomial kernel must be a positive integer.')
end
kfunargs = {pval};
setPoly = true;
case 7 % mlpparams
if numel(pval)~=2
error('Bioinfo:svmtrain:BadMLPParams',...
'MLP_PARAMS must be a two element array.');
end
if ~isscalar(pval(1)) || ~isscalar(pval(2))
error('Bioinfo:svmtrain:MLPParamsNotScalar',...
'The parameters of the multi-layer perceptron kernel must be scalar.');
end
kfunargs = {pval(1),pval(2)};
setMLP = true;
end
end
end
end
if setPoly ~usePoly
warning('Bioinfo:svmtrain:PolyOrderNotPolyKernel',...
'You specified a polynomial order but not a polynomial kernel');
end
if setMLP ~useMLP
warning('Bioinfo:svmtrain:MLPParamNotMLPKernel',...
'You specified MLP parameters but not an MLP kernel');
end
% plot the data if requested
if plotflag
[hAxis,hLines] = svmplotdata(training,g);
legend(hLines,cellstr(groupString));
end
% calculate kernel function
try
kx = feval(kfun,training,training,kfunargs{:});
% ensure function is symmetric
kx = (kx+kx')/2;
catch
error('Bioinfo:svmtrain:UnknownKernelFunction',...
'Error calculating the kernel function:\n%s\n', lasterr);
end
% create Hessian
% add small constant eye to force stability
H =((g*g').*kx) + sqrt(eps(class(training)))*eye(n);
if useQuadprog
% The large scale solver cannot handle this type of problem, so turn it
% off.
qp_opts = optimset(qp_opts,'LargeScale','Off');
% X=QUADPROG(H,f,A,b,Aeq,beq,LB,UB,X0,opts)
alpha = quadprog(H,-ones(n,1),[],[],...
g',0,zeros(n,1),inf *ones(n,1),zeros(n,1),qp_opts);
% The support vectors are the non-zeros of alpha
svIndex = find(alpha sqrt(eps));
sv = training(svIndex,:);
% calculate the parameters of the separating line from the support
% vectors.
alphaHat = g(svIndex).*alpha(svIndex);
% Calculate the bias by applying the indicator function to the support
% vector with largest alpha.
[maxAlpha,maxPos] = max(alpha); %#ok
bias = g(maxPos) - sum(alphaHat.*kx(svIndex,maxPos));
% an alternative method is to average the values over all support vectors
% bias = mean(g(sv)' - sum(alphaHat(:,ones(1,numSVs)).*kx(sv,sv)));
% An alternative way to calculate support vectors is to look for zeros of
% the Lagrangians (fifth output from QUADPROG).
%
% [alpha,fval,output,exitflag,t] = quadprog(H,-ones(n,1),[],[],...
% g',0,zeros(n,1),inf *ones(n,1),zeros(n,1),opts);
%
% sv = t.lower sqrt(eps) t.upper sqrt(eps);
else % Least-Squares
% now build up compound matrix for solver
A = [0 g';g,H];
b = [0;ones(size(g))];
x = A\b;
% calculate the parameters of the separating line from the support
% vectors.
sv = training;
bias = x(1);
alphaHat = g.*x(2:end);
end
svm_struct.SupportVectors = sv;
svm_struct.Alpha = alphaHat;
svm_struct.Bias = bias;
svm_struct.KernelFunction = kfun;
svm_struct.KernelFunctionArgs = kfunargs;
svm_struct.GroupNames = groupnames;
svm_struct.FigureHandles = [];
if plotflag
hSV = svmplotsvs(hAxis,svm_struct);
svm_struct.FigureHandles = {hAxis,hLines,hSV};
end
第一步:下載java版libsvm3.12,解壓。
第二步:打開java文件夾
第三步:建立項目,引用lib.svm包
第五步:把第二步中的文件夾中四個文件復(fù)制到一個自定義的包中
第六步:寫程序調(diào)用,代碼如下,貼出來供大家學(xué)習(xí),有不對的地方,歡迎拍磚。
import java.io.IOException;
import libsvm.svm;
import libsvm.svm_model;
public class SVMTest {
public static void main(String[] args) throws IOException {
svm_train svmt = new svm_train();
svm_predict svmp = new svm_predict();
String[] argvTrain = {
"C:\\Users\\baolong\\Desktop\\KDD\\other\\svm\\train\\TR1.data",// 訓(xùn)練文件
"C:\\Users\\baolong\\Desktop\\KDD\\other\\svm\\model\\MO1.model"http:// 模型文件
};
String[] argvPredict = {
"C:\\Users\\baolong\\Desktop\\KDD\\other\\svm\\predict\\PR1.data",// 預(yù)測文件
"C:\\Users\\baolong\\Desktop\\KDD\\other\\svm\\model\\MO1.model", // 模型文件
"C:\\Users\\baolong\\Desktop\\KDD\\other\\svm\\result\\RE1.out" // 預(yù)測結(jié)果文件
};
try {
svmt.main(argvTrain);
svmp.main(argvPredict);
} catch (IOException e) {
e.printStackTrace();
}
double[] record = { -1, 12, 12, 78 };
libsvm.svm_model model = svm
.svm_load_model("C:\\Users\\baolong\\Desktop\\KDD\\other\\svm\\model\\MO1.model");
System.out.println(svmp.predictPerRecord(record, model));
}
}
網(wǎng)站題目:支持向量機java代碼 支持向量機代碼實現(xiàn)
網(wǎng)頁網(wǎng)址:http://muchs.cn/article8/doedsop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、云服務(wù)器、小程序開發(fā)、網(wǎng)頁設(shè)計公司、全網(wǎng)營銷推廣、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)