예제 #1
0
func (nb *NaiveBayes) Predict(X *mat64.Dense) []Prediction {
	nSamples, _ := X.Dims()

	prediction := []Prediction{}

	for i := 0; i < nSamples; i++ {
		scores := map[int]float64{}
		for langIdx, _ := range nb.params.LangsCount {
			scores[langIdx] = nb.tokensProba(X.Row(nil, i), langIdx) + nb.langProba(langIdx)
		}

		bestScore := scores[0]
		bestLangIdx := 0

		for langIdx, score := range scores {
			if score > bestScore {
				bestScore = score
				bestLangIdx = langIdx
			}
		}

		prediction = append(prediction, Prediction{
			Label:    bestLangIdx,
			Language: "TODO: PENDING",
			Score:    bestScore,
		})
	}

	return prediction
}
예제 #2
0
파일: util.go 프로젝트: timkaye11/glasso
func removeRow(df *mat64.Dense, row int) *mat64.Dense {
	r, c := df.Dims()
	if row > r || row < 0 {
		panic("Row Index not supported")
	}

	cop := mat64.NewDense(r-1, c, nil)

	m := 0

	for i := 0; i < r; i++ {
		if i != row {
			cop.SetRow(m, df.Row(nil, i))
			m++
		}
	}

	return cop
}