MCPcopy Create free account
hub / github.com/datastream/libsvm / SVM_predict_probability

Method SVM_predict_probability

svm.go:2356–2393  ·  view source on GitHub ↗
(model *SVM_Model, x []SVM_Node, prob_estimates []float64)

Source from the content-addressed store, hash-verified

2354}
2355
2356func (this *SVM) SVM_predict_probability(model *SVM_Model, x []SVM_Node, prob_estimates []float64) float64 {
2357 var rst float64
2358 if (model.param.svm_type == C_SVC ||
2359 model.param.svm_type == NU_SVC) &&
2360 model.probA != nil && model.probB != nil {
2361 var i int
2362 nr_class := model.nr_class
2363 dec_values := make([]float64, nr_class*(nr_class-1)/2)
2364 this.SVM_predict_values(model, x, dec_values)
2365
2366 min_prob := float64(1e-7)
2367 pairwise_prob := make([][]float64, nr_class)
2368 for i = range pairwise_prob {
2369 pairwise_prob[i] = make([]float64, nr_class)
2370 }
2371
2372 k := 0
2373 for i = 0; i < nr_class; i++ {
2374 for j := i + 1; j < nr_class; j++ {
2375 pairwise_prob[i][j] = math.Min(math.Max(this.sigmoid_predict(dec_values[k], model.probA[k], model.probB[k]), min_prob), 1-min_prob)
2376 pairwise_prob[j][i] = 1 - pairwise_prob[i][j]
2377 k++
2378 }
2379 }
2380 this.multiclass_probability(nr_class, pairwise_prob, prob_estimates)
2381
2382 prob_max_idx := 0
2383 for i = 1; i < nr_class; i++ {
2384 if prob_estimates[i] > prob_estimates[prob_max_idx] {
2385 prob_max_idx = i
2386 }
2387 }
2388 rst = float64(model.label[prob_max_idx])
2389 } else {
2390 rst = this.SVM_predict(model, x)
2391 }
2392 return rst
2393}
2394
2395func (this *SVM) SVM_save_model(model_file_name string, model *SVM_Model) {
2396

Callers 1

SVM_cross_validationMethod · 0.95

Calls 4

SVM_predict_valuesMethod · 0.95
sigmoid_predictMethod · 0.95
SVM_predictMethod · 0.95

Tested by

no test coverage detected