MCPcopy Index your code
hub / github.com/clips/pattern / svm_train

Function svm_train

pattern/vector/svm/libsvmutil.py:80–165  ·  view source on GitHub ↗

svm_train(y, x [, options]) -> model | ACC | MSE svm_train(prob [, options]) -> model | ACC | MSE svm_train(prob, param) -> model | ACC| MSE Train an SVM model from data (y, x) or an svm_problem prob using 'options' or an svm_parameter param. If '-v' is specified in 'options' (i.e., cros

(arg1, arg2=None, arg3=None)

Source from the content-addressed store, hash-verified

78 return (ACC, MSE, SCC)
79
80def svm_train(arg1, arg2=None, arg3=None):
81 """
82 svm_train(y, x [, options]) -> model | ACC | MSE
83 svm_train(prob [, options]) -> model | ACC | MSE
84 svm_train(prob, param) -> model | ACC| MSE
85
86 Train an SVM model from data (y, x) or an svm_problem prob using
87 'options' or an svm_parameter param.
88 If '-v' is specified in 'options' (i.e., cross validation)
89 either accuracy (ACC) or mean-squared error (MSE) is returned.
90 options:
91 -s svm_type : set type of SVM (default 0)
92 0 -- C-SVC (multi-class classification)
93 1 -- nu-SVC (multi-class classification)
94 2 -- one-class SVM
95 3 -- epsilon-SVR (regression)
96 4 -- nu-SVR (regression)
97 -t kernel_type : set type of kernel function (default 2)
98 0 -- linear: u'*v
99 1 -- polynomial: (gamma*u'*v + coef0)^degree
100 2 -- radial basis function: exp(-gamma*|u-v|^2)
101 3 -- sigmoid: tanh(gamma*u'*v + coef0)
102 4 -- precomputed kernel (kernel values in training_set_file)
103 -d degree : set degree in kernel function (default 3)
104 -g gamma : set gamma in kernel function (default 1/num_features)
105 -r coef0 : set coef0 in kernel function (default 0)
106 -c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
107 -n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
108 -p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)
109 -m cachesize : set cache memory size in MB (default 100)
110 -e epsilon : set tolerance of termination criterion (default 0.001)
111 -h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)
112 -b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)
113 -wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)
114 -v n: n-fold cross validation mode
115 -q : quiet mode (no outputs)
116 """
117 prob, param = None, None
118 if isinstance(arg1, (list, tuple)):
119 assert isinstance(arg2, (list, tuple))
120 y, x, options = arg1, arg2, arg3
121 param = svm_parameter(options)
122 prob = svm_problem(y, x, isKernel=(param.kernel_type == PRECOMPUTED))
123 elif isinstance(arg1, svm_problem):
124 prob = arg1
125 if isinstance(arg2, svm_parameter):
126 param = arg2
127 else:
128 param = svm_parameter(arg2)
129 if prob == None or param == None:
130 raise TypeError("Wrong types for the arguments")
131
132 if param.kernel_type == PRECOMPUTED:
133 for xi in prob.x_space:
134 idx, val = xi[0].index, xi[0].value
135 if xi[0].index != 0:
136 raise ValueError('Wrong input format: first column must be 0:sample_serial_number')
137 if val <= 0 or val > prob.n:

Callers

nothing calls this directly

Calls 5

svm_parameterClass · 0.85
svm_problemClass · 0.85
printFunction · 0.85
evaluationsFunction · 0.70
toPyModelFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…