我是 go 新手,但我发现golearn项目在 github 上有很多星星,所以我决定尝试简单的分类问题。但是第一次尝试指针问题出现在Train
方法中,我不确定它是golearn绑定中的错误还是与错误设置有关。
这是代码的简化版本:
package main
import (
_ "github.com/sjwhitworth/golearn/base"
liblinear "github.com/sjwhitworth/golearn/linear_models"
)
func main() {
labels, features := getFeatures()
vocabulary := createVocabulary(features)
words_matrix := countedMatrix(features, vocabulary)
fmt.Println("labels:", labels)
fmt.Println("words matrix:", words_matrix)
solver_type := liblinear.L2R_LR_DUAL
C := 10.0
eps := 0.01
bias := -1.0
parameter := liblinear.NewParameter(solver_type, C, eps)
problem := liblinear.NewProblem(words_matrix, categories, bias)
model := liblinear.Train(problem, parameter)
prediction_vector := countedVector(tokenize("something to predict here"), vocabulary)
fmt.Println("prediction vector:", prediction_vector)
prediction := liblinear.Predict(model, prediction_vector)
fmt.Println("prediction:", prediction)
}
这是我得到的输出:
labels: [6 8 9 10 11 12 14 15 16 17]
words matrix: [[0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0] [0 1 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0] [0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0] [0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1] [1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0] [0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 1 1 0 0 1 1] [0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1]]
panic: runtime error: cgo argument has Go pointer to Go pointer
goroutine 1 [running]:
panic(0x83d620, 0xc8200d7510)
/usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
github.com/sjwhitworth/golearn/linear_models.Train(0xc820102420, 0xc820015e80, 0xa)
/home/me/gocode/src/github.com/sjwhitworth/golearn/linear_models/liblinear.go:61 +0x11d
main.main()
/home/me/gocode/src/mlservice/main.go:144 +0x62b
exit status 2
我应该报告问题还是修复代码(如果可以修复,请帮助我)