私はgoの初心者ですが、githubで多くの星を持つgolearnプロジェクトを見つけたので、単純な分類問題で試してみることにしました。しかし、最初の試行でポインターの問題が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
問題を報告するか、コードを修正する必要があります (修正が可能な場合は助けてください)