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

Method SVM_train

svm.go:1877–2119  ·  view source on GitHub ↗
(prob *SVM_Problem, param *SVM_Parameter)

Source from the content-addressed store, hash-verified

1875}
1876
1877func (this *SVM) SVM_train(prob *SVM_Problem, param *SVM_Parameter) *SVM_Model {
1878
1879 model := new(SVM_Model)
1880 model.param = param
1881
1882 if param.svm_type == ONE_CLASS || param.svm_type == EPSILON_SVR || param.svm_type == NU_SVR {
1883 // regression or one-class-svm
1884 model.nr_class = 2
1885 model.label = nil
1886 model.nSV = nil
1887 model.probA = nil
1888 model.probB = nil
1889 model.sv_coef = make([][]float64, 1)
1890
1891 if param.probability == 1 && (param.svm_type == EPSILON_SVR || param.svm_type == NU_SVR) {
1892 model.probA = make([]float64, 1)
1893 model.probA[0] = this.SVM_svr_probability(prob, param)
1894 }
1895
1896 f := this.SVM_train_one(prob, param, 0, 0)
1897 model.rho = make([]float64, 1)
1898 model.rho[0] = f.rho
1899
1900 nSV := 0
1901 var i int
1902 for i = 0; i < prob.l; i++ {
1903 if math.Abs(f.alpha[i]) > 0 {
1904 nSV++
1905 }
1906 }
1907 model.l = nSV
1908 model.SV = make([][]SVM_Node, nSV)
1909 model.sv_coef[0] = make([]float64, nSV)
1910 j := 0
1911 for i = 0; i < prob.l; i++ {
1912 if math.Abs(f.alpha[i]) > 0 {
1913 model.SV[j] = prob.x[i]
1914 model.sv_coef[0][j] = f.alpha[i]
1915 j++
1916 }
1917 }
1918 } else {
1919 // classification
1920 l := prob.l
1921 tmp_nr_class := make([]int, 1)
1922 tmp_label := make([][]int, 1)
1923 tmp_start := make([][]int, 1)
1924 tmp_count := make([][]int, 1)
1925 perm := make([]int, l)
1926
1927 // group training data of the same class
1928 this.SVM_group_classes(prob, tmp_nr_class, tmp_label, tmp_start, tmp_count, perm)
1929 nr_class := tmp_nr_class[0]
1930 label := tmp_label[0]
1931 start := tmp_start[0]
1932 count := tmp_count[0]
1933
1934 if nr_class == 1 {

Callers 2

SVM_cross_validationMethod · 0.95

Calls 4

SVM_svr_probabilityMethod · 0.95
SVM_train_oneMethod · 0.95
SVM_group_classesMethod · 0.95

Tested by

no test coverage detected