MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / getFeatureWeights

Method getFeatureWeights

src/openms/source/ANALYSIS/SVM/SimpleSVM.cpp:288–318  ·  view source on GitHub ↗

only works in classification mode

Source from the content-addressed store, hash-verified

286
287// only works in classification mode
288void SimpleSVM::getFeatureWeights(map<String, double>& feature_weights) const
289{
290 if (model_ == nullptr)
291 {
292 throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
293 "SVM model has not been trained (use the "
294 "'setup' method)");
295 }
296 Size k = model_->nr_class;
297 if (k > 2)
298 {
299 throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
300 "Output of feature weights is currently only "
301 "supported for two-class classification");
302 }
303
304 feature_weights.clear();
305 Size n_sv = model_->l; // number of support vectors
306 for (Size l = 0; l < n_sv; ++l)
307 {
308 double sv_coef = model_->sv_coef[0][l];
309 // LIBSVM uses a sparse representation for data (incl. support vectors):
310 for (Size n = 0; ; ++n)
311 {
312 const struct svm_node& node = model_->SV[l][n];
313 if (node.index == -1) break;
314 const String& predictor_name = predictor_names_[node.index - 1];
315 feature_weights[predictor_name] += sv_coef * node.value;
316 }
317 }
318}
319
320void SimpleSVM::scaleData_(PredictorMap& predictors)
321{

Callers 3

quantifyFraction_Method · 0.80
classifyFeatures_Method · 0.80
SimpleSVM_test.cppFile · 0.80

Calls 1

clearMethod · 0.45

Tested by

no test coverage detected