예제 #1
0
파일: linear.go 프로젝트: lazywei/lineargo
// double predict_probability(const struct model *model_, const struct feature_node *x, double* prob_estimates);
func PredictProba(model *Model, X *mat64.Dense) *mat64.Dense {
	nRows, nCols := X.Dims()
	nrClasses := int(C.get_nr_class(model.cModel))

	cX := mapCDouble(X.RawMatrix().Data)
	y := mat64.NewDense(nRows, nrClasses, nil)

	result := doubleToFloats(C.call_predict_proba(
		model.cModel, &cX[0], C.int(nRows), C.int(nCols), C.int(nrClasses)),
		nRows*nrClasses)
	for i := 0; i < nRows; i++ {
		y.SetRow(i, result[i*nrClasses:(i+1)*nrClasses])
	}
	return y
}
예제 #2
0
// double predict_probability(const struct model *model_, const struct feature_node *x, double* prob_estimates);
func PredictProba(model *Model, X *mat64.Dense) *mat64.Dense {
	nRows, _ := X.Dims()
	nrClasses := int(C.get_nr_class(model.cModel))

	cXs := toFeatureNodes(X)
	y := mat64.NewDense(nRows, nrClasses, nil)

	proba := make([]C.double, nrClasses, nrClasses)
	for i, cX := range cXs {
		C.predict_probability(model.cModel, cX, &proba[0])
		for j := 0; j < nrClasses; j++ {
			y.Set(i, j, float64(proba[j]))
		}
	}
	return y
}