1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-26 13:49:14 +08:00

catching nInstances == 0

This commit is contained in:
Ayush 2020-08-01 11:36:53 +05:30
parent 9d1ac82a40
commit 6a42fcd4ae

View File

@ -90,6 +90,9 @@ func computeEntropyAndModeLabel(y []int64, labels []int64) (float64, int64) {
} }
func calculateClassificationLoss(y []int64, labels []int64, criterion string) (float64, int64, error) { func calculateClassificationLoss(y []int64, labels []int64, criterion string) (float64, int64, error) {
if len(y) == 0 {
return 0, 0, errors.New("Need atleast 1 value to compute impurity")
}
if criterion == GINI { if criterion == GINI {
loss, modeLabel := computeGiniImpurityAndModeLabel(y, labels) loss, modeLabel := computeGiniImpurityAndModeLabel(y, labels)
return loss, modeLabel, nil return loss, modeLabel, nil