Skip to content

Commit

Permalink
lr: update LR data normalization to divide by the max value (scale) (#…
Browse files Browse the repository at this point in the history
…954)

Signed-off-by: Marcelo Amaral <[email protected]>
  • Loading branch information
marceloamaral authored Oct 2, 2023
1 parent 1360266 commit 7b801bf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions pkg/model/estimator/local/lr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"encoding/json"
"fmt"
"io"
"math"
"net/http"
"os"

Expand Down Expand Up @@ -81,9 +80,8 @@ type CategoricalFeature struct {
Weight float64 `json:"weight"`
}
type NormalizedNumericalFeature struct {
Mean float64 `json:"mean"`
Variance float64 `json:"variance"`
Weight float64 `json:"weight"`
Scale float64 `json:"scale"` // to normalize the data
Weight float64 `json:"weight"`
}

// getIndexedWeights maps weight index with usageMetrics
Expand Down Expand Up @@ -112,8 +110,7 @@ func (weights ModelWeights) predict(usageMetricNames []string, usageMetricValues
if coeff.Weight == 0 {
continue
}
// TODO: review this normalization, when the mean is higher than the val, the normalized value will be negative. We probably do not want this.
normalizedX := (vals[index] - coeff.Mean) / math.Sqrt(coeff.Variance)
normalizedX := vals[index] / coeff.Scale
power += coeff.Weight * normalizedX
}
powers = append(powers, power)
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/estimator/local/lr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ var (
},
}
SampleCoreNumericalVars = map[string]NormalizedNumericalFeature{
"cpu_cycles": {Weight: 1.0, Mean: 0, Variance: 1},
"cpu_cycles": {Weight: 1.0, Scale: 1},
}
SampleDramNumbericalVars = map[string]NormalizedNumericalFeature{
"cache_miss": {Weight: 1.0, Mean: 0, Variance: 1},
"cache_miss": {Weight: 1.0, Scale: 1},
}
SampleComponentWeightResponse = ComponentModelWeights{
collector_metric.CORE: genWeights(SampleCoreNumericalVars),
Expand Down

0 comments on commit 7b801bf

Please sign in to comment.