loss for multi log reg
This commit is contained in:
parent
bf43ecee22
commit
cde2e6fe99
|
@ -56,5 +56,5 @@ func TestMCLogisticRegression(t *testing.T) {
|
|||
regr.Fit(XDense, YDense)
|
||||
// fmt.Println(regr.Weights, regr.Bias)
|
||||
yPred := regr.Predict(XDense)
|
||||
fmt.Println(YDense, yPred) //, regr.Loss(YDense, yPred))
|
||||
fmt.Println(YDense, yPred, regr.Loss(YDense, yPred))
|
||||
}
|
||||
|
|
|
@ -42,3 +42,15 @@ func (regr *MCLogisticRegression) Predict(x mat.Matrix) mat.Matrix {
|
|||
wg.Wait()
|
||||
return probs
|
||||
}
|
||||
|
||||
func (regr *MCLogisticRegression) Loss(yTrue, yPred mat.Matrix) float64 {
|
||||
loss := 0.
|
||||
for j := 0; j < regr.cols; j++ {
|
||||
yj := mat.Col(nil, j, yTrue)
|
||||
Y := mat.NewDense(len(yj), 1, yj)
|
||||
ypj := mat.Col(nil, j, yPred)
|
||||
YP := mat.NewDense(len(ypj), 1, ypj)
|
||||
loss += regr.Models[j].Loss(Y, YP)
|
||||
}
|
||||
return loss / float64(regr.cols)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue